Skip to content

Instantly share code, notes, and snippets.

View hyfather's full-sized avatar

Nikhil Mungel hyfather

View GitHub Profile
@hyfather
hyfather / pipeline.go
Created April 6, 2018 23:13
Go Pipelines
package main
import (
"log"
"sync"
"time"
)
func main() {
log.Println("start")
@hyfather
hyfather / init.el
Last active August 29, 2015 14:01
my_emacs_init.el
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/") t)
(package-initialize)
;; Use Shift + <Arrow Keys> for moving between buffers
(windmove-default-keybindings)
(setq windmove-wrap-around t)
;; Because Shift-Up is broken on xterm
@hyfather
hyfather / github_stacktrace
Created June 20, 2012 11:17
github post receive hook stacktrace
% git push
Counting objects: 26, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (14/14), done.
Writing objects: 100% (15/15), 20.28 KiB, done.
Total 15 (delta 9), reused 0 (delta 0)
remote: /data/github/current/vendor/gems/ruby/1.8/gems/redis-2.2.0/lib/redis/connection/hiredis.rb:23:in `connect': Timeout::Error (Timeout::Error)
remote: from /data/github/current/vendor/gems/ruby/1.8/gems/redis-2.2.0/lib/redis/client.rb:204:in `establish_connection'
remote: from /data/github/current/vendor/gems/ruby/1.8/gems/redis-2.2.0/lib/redis/client.rb:23:in `connect'
remote: from /data/github/current/vendor/gems/ruby/1.8/gems/redis-2.2.0/lib/redis/client.rb:224:in `ensure_connected'
@hyfather
hyfather / ssh-copy-id
Created December 16, 2011 08:05
ssh-copy-id
#!/bin/bash
ssh-add
ssh $1 "mkdir -p .ssh && touch .ssh/authorized_keys && echo `ssh-add -L` >> .ssh/authorized_keys"
# keep this file in the PATH. like in /usr/bin.
@hyfather
hyfather / euler_three.rb
Created November 14, 2011 06:20
My solution to problem #3 on projecteuler.net
def factorize(list, num, p)
while true
list.each_with_index { |e, i| list[i] = 0 if e!=p && e%p == 0 }
list.each{|e| p = e and break if e > p}
if num % p == 0
# p num
return factorize(list[p..Math.sqrt(num/=p)], num, p)
end
return num if list.empty?
end
@hyfather
hyfather / euler_two.rb
Created November 13, 2011 20:35
My solution to problem #2 on projecteuler.net
class Array
def fibselect(&block)
o, i, array = 0, 1, []
while i < length
o, i = i, i+o
array << self[i]
end
array.compact.select &block
end
end
@hyfather
hyfather / euler_one.rb
Created November 13, 2011 20:34
My solution to problem #1 on projecteuler.net
p [1..999].select{|e| e%3 == 0 || e%5 == 0}.inject(:+)
@hyfather
hyfather / euler_eight.rb
Created November 9, 2011 04:49
My solution to problem #8 on projecteuler.net
#"Find the greatest product of five consecutive digits in the 1000-digit number."
# http://projecteuler.net/problem=8
big = "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522\
74430435576689664895044524452316173185640309871112172238311362229893423380308135336276614282806444486645238749303589072962904915604407723907138105158593079608667017242712188399879790879227492190169\
97208880937766572733300105336788122023542180975125454059475224352584907711670556013604839586446706324415722155397536978179778461740649551492908625693219784686224828397224137565705605749026140797296\
86524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054\
4217506941658960408071984038509624554443629812309878799272442849091888458015616609791913387549920052406368991
@hyfather
hyfather / emacs_readline_keybindings.md
Created October 25, 2011 04:40
Shortcuts with the emacs readline

M stands for the Meta key. Commonly represented by the Alt/Option/Esc key on your keyboard.
C stands for the Control key.
Example -- C-k means 'hit k while keeping Control pressed.'

M-.
Yank the last argument to the previous command.

M-C-y
Yank the first argument to the previous command.

@hyfather
hyfather / merging_hashes_explained.rb
Created October 24, 2011 14:35
Explains how all Hashes in an Array can be merged.
[{:a => 'alpha'}, {:b => 'beta'}, {:c => 'charlie'}].map(&:to_a)
#=> [[[:a, "alpha"]], [[:b, "beta"]], [[:c, "charlie"]]]
flat_array = [{:a => 'alpha'}, {:b => 'beta'}, {:c => 'charlie'}].map(&:to_a).flatten
#=> [:a, "alpha", :b, "beta", :c, "charlie"]
Hash[*flat_array]
#=> {:a=>"alpha", :b=>"beta", :c=>"charlie"}