Skip to content

Instantly share code, notes, and snippets.

View sandys's full-sized avatar

Sandeep Srinivasa sandys

View GitHub Profile
@sandys
sandys / table_to_csv.rb
Created October 18, 2012 10:04
convert a html table to CSV using ruby
# run using ```rvm jruby-1.6.7 do jruby "-J-Xmx2000m" "--1.9" tej.rb```
require 'rubygems'
require 'nokogiri'
require 'csv'
f = File.open("/tmp/preview.html")
doc = Nokogiri::HTML(f)
csv = CSV.open("/tmp/output.csv", 'w',{:col_sep => ",", :quote_char => '\'', :force_quotes => true})
@sandys
sandys / go-mtpfs.md
Created October 13, 2012 12:23
Mount the HTC One X on Linux (Ubuntu 12.04 Precise)
sudo apt-get install golang git mercurial
git clone https://github.com/hanwen/go-mtpfs.git
cd go-mtpfs
go build
sudo mv go-mtpfs /usr/local/sbin/go-mtpfs 
sudo chmod a+x /usr/local/sbin/go-mtpfs
sudo mkdir /media/mtp
sudo chmod 775 /media/mtp
sudo /usr/local/sbin/go-mtpfs -allow-other=true /media/mtp
@sandys
sandys / postsql.sql
Created October 12, 2012 15:52 — forked from tobyhede/postsql.sql
PostgreSQL as JSON Document Store
-- PostgreSQL 9.2 beta (for the new JSON datatype)
-- You can actually use an earlier version and a TEXT type too
-- PL/V8 http://code.google.com/p/plv8js/wiki/PLV8
-- Inspired by
-- http://people.planetpostgresql.org/andrew/index.php?/archives/249-Using-PLV8-to-index-JSON.html
-- http://ssql-pgaustin.herokuapp.com/#1
-- JSON Types need to be mapped into corresponding PG types
--
@sandys
sandys / R_code.R
Created October 10, 2012 09:16
Coursera operations management notes
d <- data.frame(PT=c(3,2,5,1))
d <- data.frame(d, capacity=1/d$PT)
d$flow_rate <- min(d$capacity) # no demand numbers here
d <- data.frame(d, process_capacity=min(d$capacity))
d <- data.frame(d, cycle_time=1/d$process_capacity)
d <- data.frame(d, dlc=sum(d$PT))
d <- data.frame(d, idle_time=d$cycle_time-d$PT)
d <- data.frame(d, total_idle_time=sum(d$idle_time))
d <- data.frame(d, total_labor_content=sum(d$PT))
d <- data.frame(d, labor_util=d$total_labor_content/(d$total_labor_content+d$total_idle_time))
@sandys
sandys / computing_data_analysis_notes.md
Created September 26, 2012 10:01
notes for Computing for Data Analysis coursera course

using logical indexes

in1 <- c(TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE)
x[in1]```

* single [] operator returns the same class - except in matrix. To get the same behavior in matrix, set ``` drop=FALSE``` attribute
    * ```x[1,,drop=FALSE] ``` 
* ```attributes(y) ``` to list all attributes of a data strucuture
    * ``` attr(y, "class")``` to print out one particular attribute
* lists also work as hashes ```x &lt;- list(foo = 1:4, bar=0.6) x$foo ```
@sandys
sandys / scalafun.md
Created September 24, 2012 18:06
Notes for Scala functional programming coursera
  • if CBV terminates, then so does CBN - since CBN will evaluate less than or equal parameters than CBV
  • CBV avoids repeated recomputation of values
  • force scala to do CBN, by defining def fun(x:Int, y:=>Int)
  • disjunction and conjunction (&& and ||) are short-circuit operators - the right side will only be evaluated in certain cases.
  • in certain cases like
    if(r==0)
      return 1
    there is an error Scala: type mismatch; found : Unit required: Boolean
    • this happens because you have to have an else clause, otherwise the type checker doesn't know what the return type is when it's not the case
  • return fn(a-1) is tail recursive but return n * fn(a-1) is not
@sandys
sandys / fp_ruby_rc4.rb
Created September 20, 2012 10:56
an example of Format Preserving Encryption in Ruby using RC4 and pack. The important thing is to keep key length to be a power of 2
require 'openssl'
c = OpenSSL::Cipher::Cipher.new("rc4-40")
serial = 4000987
puts " *********** SERIAL NUMBER = #{serial}"
c.encrypt
c.key = "fdkjgfdoi4tu45fkgkljfg9485439tkjfgnjdshfghwhe54350gfgklkgje34324nkjdfhk45845843543k5kdjfk3454958439kkfkglgkttpoeoidsad49584305ldkfsdjf42jkndfl"
padded_serial = "%015d" % serial
padded_serial_array = [padded_serial.slice(0,10).to_i, padded_serial.slice(10,15).to_i]
@sandys
sandys / etc_sites_enabled_default.nginx
Created September 4, 2012 06:40
Bulletproof Wordpress installation
proxy_cache_path /var/lib/nginx/cache/staticfiles levels=1:2 keys_zone=staticfilecache:60m inactive=90m max_size=50m;
proxy_temp_path /var/lib/nginx/proxy;
proxy_connect_timeout 30;
proxy_read_timeout 120;
proxy_send_timeout 120;
map $http_cookie $logged_in {
default 0;
~wordpress_logged_in 1; # Wordpress session cookie
@sandys
sandys / java_debugging.md
Created August 17, 2012 09:19
Java debugging howtos

locate /usr/java/tomcat/temp/hsperfdata_tomcat/

to get processid of tomcat jps -J-Djava.io.tmpdir=/usr/java/tomcat/temp

/usr/java/jdk1.6.0_24/bin/jmap -J-Djava.io.tmpdir=/usr/local/tomcat-instance/traduscms/temp -heap 23420

sudo -u root /usr/java/jdk1.6.0_24/bin/jstack -J-Djava.io.tmpdir=/usr/local/tomcat-instance/tradusgv/temp -J-d64 10960

@sandys
sandys / gist:3351411
Created August 14, 2012 18:15 — forked from l0b0/gist:3217470
Simple merge example
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
cd "$(mktemp --directory)"
git init
cat > test.txt <<EOF
alfa
bravo
charlie