Skip to content

Instantly share code, notes, and snippets.

View sandys's full-sized avatar

Sandeep Srinivasa sandys

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / clean_csv.rb
Created October 18, 2012 10:06
Clean a dirty CSV file using ruby
require 'fastercsv'
require 'csv'
require 'net/http'
require 'sanitize'
#CSV_FILE_PATH = File.join(File.dirname(__FILE__), 'c2i.csv')
CSV_FILE_PATH = File.join('/tmp', 'Computers_Accessories_Master.csv')
=begin
@sandys
sandys / gist:3974478
Created October 29, 2012 16:07
Debian 6 fresh setup
* aptitude install sudo
* add the following to /etc/apt/sources.list
<pre>
deb http://ftp.br.debian.org/debian squeeze main
deb-src http://ftp.br.debian.org/debian squeeze main
deb http://ftp.br.debian.org/debian squeeze-updates main
deb-src http://ftp.br.debian.org/debian squeeze-updates main
deb http://security.debian.org/ squeeze/updates main
@sandys
sandys / ssh_agent_ubuntu.md
Created October 30, 2012 11:49
Use ssh-agent and ssh-add on Ubuntu without annoying gnome-keyring

sudo gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory --type bool --set /apps/gnome-keyring/daemon-components/secrets FALSE
sudo gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory --type bool --set /apps/gnome-keyring/daemon-components/pkcs11 FALSE
sudo gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory --type bool --set /apps/gnome-keyring/daemon-components/ssh FALSE

eval `ssh-agent`

echo $SSH_AUTH_SOCK #copy the path that is displayed as a result

#whenever you want a new shell: SSH_AUTH_SOCK= ssh xxx@2.2.2.2

@sandys
sandys / debian_6_ramnode.md
Created December 13, 2012 08:22
ruby installation on debian 6 vm

aptitude install autoconf automake bison build-essential curl git-core libapr1 libaprutil1 libc6-dev libltdl-dev libreadline6 libreadline6-dev libsqlite3-0 libsqlite3-dev libssl-dev libtool libxml2-dev libxslt-dev libxslt1-dev libyaml-dev ncurses-dev openssl sqlite3 zlib1g zlib1g-dev

git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv

in .zshenv

export PATH="/usr/local/rbenv/bin:$PATH" eval "$(rbenv init -)"

on cmdline