Should I buffer the InputStream or the InputStreamReader?

r1 is more efficient. The InputStreamReader itself doesn’t have a large buffer. The BufferedReader can be set to have a larger buffer than InputStreamReader. The InputStreamReader in r2 would act as a bottleneck. In a nut: you should read the data through a funnel, not through a bottle. Update: here’s a little benchmark program, just … Read more

Haskell: read input character from console immediately, not after newline

Yes, it’s a bug. Here’s a workaround to save folks clicking and scrolling: {-# LANGUAGE ForeignFunctionInterface #-} import Data.Char import Foreign.C.Types getHiddenChar = fmap (chr.fromEnum) c_getch foreign import ccall unsafe “conio.h getch” c_getch :: IO CInt So you can replace calls to getChar with calls to getHiddenChar. Note this is a workaround just for ghc/ghci … Read more

What does “select((select(s),$|=1)[0])” do in Perl?

It’s a nasty little idiom for setting autoflush on a filehandle other than STDOUT. select() takes the supplied filehandle and (basically) replaces STDOUT with it, and it returns the old filehandle when it’s done. So (select($s),$|=1) redirects the filehandle (remember select returns the old one), and sets autoflush ($| = 1). It does this in … Read more

Android – How to tell when MediaPlayer is buffering

Like below (API level ≥ 9): mp.setOnInfoListener(new OnInfoListener() { @Override public boolean onInfo(MediaPlayer mp, int what, int extra) { switch (what) { case MediaPlayer.MEDIA_INFO_BUFFERING_START: loadingDialog.setVisibility(View.VISIBLE); break; case MediaPlayer.MEDIA_INFO_BUFFERING_END: loadingDialog.setVisibility(View.GONE); break; } return false; } }); NOTE : There is a known bug in Android. When playing HLS stream it’s just never calls OnInfoListener or OnBuffering. … Read more

How can I check if my AVPlayer is buffering?

You can observe the values of your player.currentItem: playerItem.addObserver(self, forKeyPath: “playbackBufferEmpty”, options: .New, context: nil) playerItem.addObserver(self, forKeyPath: “playbackLikelyToKeepUp”, options: .New, context: nil) playerItem.addObserver(self, forKeyPath: “playbackBufferFull”, options: .New, context: nil) then override public func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) { if object is AVPlayerItem { switch keyPath { case “playbackBufferEmpty”: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)