Skip to content

Instantly share code, notes, and snippets.

View rraman47's full-sized avatar

Rituraj Raman rraman47

  • Bangalore, India
View GitHub Profile
@rraman47
rraman47 / gist:e36d0f5afa34b7fd808082cbe36e534e
Created February 8, 2017 05:06
Timeout when reading from a file descriptor
As an alternative to select(), for the specific case of a serial port (terminal) you can use tcsetattr() to put the file descriptor into non-canonical mode, with a read timeout.
To do this, unset the ICANON flag, and set the VTIME control character:
struct termios termios;
tcgetattr(filedesc, &termios);
@rraman47
rraman47 / gist:09ecdb2ac57e135650d9620ad55ac27c
Created January 26, 2017 08:56
install atom for ubuntu
sudo add-apt-repository ppa:webupd8team/atom
sudo apt-get update
sudo apt-get install atom
//Declare a variable named 'input_string' to hold our input.
char input_string[105];
// Read a full line of input from stdin and save it to our variable, input_string.
scanf("%[^\n]", input_string);
[^\n] causes us to read till a \n is encountered.
If you want to read 4 characters at most, or till a newline is encountered,
scanf("%4[^\n]", input_string);
@rraman47
rraman47 / gist:74d867e922fac4a1aadf6953e568d4d6
Created January 5, 2017 18:17
Make a branch the master branch
git checkout better_branch
git merge --strategy=ours master # keep the content of this branch, but record a merge
git checkout master
git merge better_branch # fast-forward master up to the merge
Finally, the better_branch becomes your master.