Skip to content

Instantly share code, notes, and snippets.

View scarecrow1123's full-sized avatar

ananda seelan scarecrow1123

View GitHub Profile
@scarecrow1123
scarecrow1123 / tmux.md
Created January 5, 2016 08:01 — forked from andreyvit/tmux.md
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

@scarecrow1123
scarecrow1123 / complete_graph.py
Last active February 20, 2016 10:08
Make a complete graph - Python one liner
def make_complete_graph(num_nodes):
"""takes number of nodes and returns a dict that represents
a complete graph(no self loops) with num_nodes"""
return {x: set([(lambda y: y)(y) for y in xrange(num_nodes) if y!= x]) for x in xrange(num_nodes)}
#remove the y!=x condition for self loops
@scarecrow1123
scarecrow1123 / sort_set_bits.py
Created February 20, 2016 10:07
Sort a list based on the number of set bits in each digit
def count_set_bits(i):
return bin(i).count('1')
def sort_set_bits(lst):
"""sorts a list based on the number of set bits in each digit"""
return sorted(lst, key=count_set_bits)
"""takes a list x and returns a list with odd integers or elements with even index"""
[i for idx,i in enumerate(x) if (type(i) is int) and (i%2 !=0 or idx%2==0)]
"""finds the shortest path that an ant could take to reach a point from another
constraint: the ant can move only to the right or up at any point
"""
grid_order = 4
grid = {}
index = {}
rev_index = {}
adj_list = {}
# tmux.conf - almost everything noted from the book "tmux Productive Mouse-Free Development" by "Brian P. Hogan"
# change default prefix to C-a and unbind C-b
set -g prefix C-a
unbind-key C-b
# to enable other programs to detect C-a(by double pressing)
bind-key C-a send-prefix
# '|' for vertical split and '-' for horizontal split
bind | split-window -h
@scarecrow1123
scarecrow1123 / vimrc
Last active August 11, 2016 11:28
A very basic vimrc
set expandtab
set shiftwidth=2
set softtabstop=2
set autoindent
syntax enable
set number "show line numbers
set cursorline "highlight current line
filetype indent on

Test mbostock's awesome bl.ocks.org

@scarecrow1123
scarecrow1123 / Classes.md
Last active January 29, 2017 18:05
Notes from Effective Java by Joshua Bloch aka jDheivam!

Classes

Reduce accessbility

Somehow the author keeps on reiterating this point the reason for which essentially boils down as below

  • The client need not know the internal implementation/representation of the class/object
  • If exposed, it would become cumbersome in the event of changing the implementation/representation of the class, which may cause several breakages in client code. On the other hand if the field was exposed through getter methods, the change in the implementation would have gone unnoticed by the client.
  • Allow public access, if neccessary only in case of static final and primitive fields.(even in this case, when the field or object itself is passed from one thread to another, one needs to exercise caution - why?)
  • But a final array field may not become immutable after all. In that case make it private and expose an unmodifiable public list field. Or make it private and provide a getter method which returns a copy of the array.

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name: