Skip to content

Instantly share code, notes, and snippets.

View naveensrinivasan's full-sized avatar

Naveen naveensrinivasan

View GitHub Profile
@naveensrinivasan
naveensrinivasan / gist:5714723
Created June 5, 2013 15:25
Sometimes wish that I could add a function to unnamed type using interface{}
func (i interface{}) PLusOne() interface{} {
if w, ok := i.(int); ok {
return w + 1
} else {
return nil
}
}
@naveensrinivasan
naveensrinivasan / Queue.go
Last active December 18, 2015 09:29
A simple Queue in go.
type Any interface{}
// Queue is a basic FIFO Queue
type Queue struct {
nodes []Any
size int
head int
tail int
count int
}
package main
import (
"fmt"
)
type Vector struct {
cnt, shift int
root node
tail List
@naveensrinivasan
naveensrinivasan / environmentasmap.go
Created June 23, 2013 22:36
Here is a code to get the environment variables as a map in go instead of slice.
package main
import (
"fmt"
"os"
"strings"
)
func main() {
getenvironment := func(data []string, getkeyval func(item string) (key, val string)) map[string]string {
@naveensrinivasan
naveensrinivasan / gist:5951642
Created July 8, 2013 19:17
my new vim bindings
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
noremap <BS> <NOP>
inoremap <Up> <NOP>
inoremap <Down> <NOP>
inoremap <Left> <NOP>
inoremap <Right> <NOP>
inoremap <Esc> <NOP>
@naveensrinivasan
naveensrinivasan / Goodreads.rb
Last active March 17, 2016 10:35
An easy way to screen scrape GoodReads recommendation's because there isn't an API.
# An easy way to get the recommendations from goodreads because there isn't an API to get the information
require 'mechanize'
require 'yaml'
require 'goodreads'
keys = YAML.load_file ENV['HOME']+'/.goodreads'
client = Goodreads::Client.new(:api_key => keys["developer_key"], :api_secret => keys["developer_secret"])
agent = Mechanize.new
page = agent.get 'http://www.goodreads.com/recommendations/'

Build your own private, encrypted, open-source Dropbox-esque sync folder

Prerequisites:

  • One or more clients running a UNIX-like OS. Examples are given for Ubuntu 12.04 LTS, although all software components are available for other platforms as well (e.g. OS X). YMMV
  • A cheap Ubuntu 12.04 VPS with storage. I recommend Backupsy, they offer 250GB storage for $5/month. Ask Google for coupon codes.

Software components used:

  • Unison for file synchronization
  • EncFS for folder encryption
@naveensrinivasan
naveensrinivasan / findkeepfile.sh
Created July 31, 2013 19:55
Finds the keep files within a given date range.
find -type f -name "*.keep" -newermt 2013-05-10 ! -newermt 2013-05-19
@naveensrinivasan
naveensrinivasan / gist:8733267
Created January 31, 2014 14:40
Compare strings
var f = File.ReadAllLines(@"c:\n\Documents\initial.csv").First().Split(',');
var s = File.ReadAllLines(@"c:\n\Documents\second.csv").First().Split(',');
f.Zip(s,(a,b) => a + "-" + b).Dump();
cinst IIS-WebServerRole -source windowsfeatures
cinst IIS-HttpCompressionDynamic -source windowsfeatures
cinst IIS-ManagementScriptingTools -source windowsfeatures
cinst IIS-WindowsAuthentication -source windowsfeatures
cinst IIS-BasicAuthentication -source windowsfeatures
cinst IIS-ASPNET -source windowsfeatures
cinst IIS-ASPNET45 -source windowsfeatures
cinst IIS-ManagementConsole -source windowsfeatures
Set-ExplorerOptions -showHidenFilesFoldersDrives -showProtectedOSFiles -showFileExtensions