Skip to content

Instantly share code, notes, and snippets.

View dvliman's full-sized avatar

David Liman dvliman

View GitHub Profile
@dvliman
dvliman / servefiles
Created August 19, 2012 17:20
file:// to http://. simple http server on your root directory
#!/usr/bin/env ruby
# thanks to jim weirich
# run ./servefiles from the root directory
require 'webrick'
include WEBrick
dir = Dir::pwd
port = (ARGV.first || (12000 + (dir.hash % 1000))).to_i
@dvliman
dvliman / scan.sh
Created August 28, 2012 20:48
scan port
scan() {
if [[ -z $1 || -z $2 ]]; then
echo "Usage: $0 <host> <port, ports, or port-range>"
return
fi
local host=$1
local ports=()
case $2 in
*-*)
@dvliman
dvliman / gist:5145258
Created March 12, 2013 17:58
daemonize
def daemonize
if RUBY_VERSION < "1.9"
exit if fork
Process.setsid
exit if fork
Dir.chdir "/"
STDIN.reopen "/dev/null"
STDOUT.reopen "/dev/null", "a"
STDERR.reopen "/dev/null", "a"
@dvliman
dvliman / gist:5333635
Created April 8, 2013 01:56
remove duplicates in $PATH
PATH=`perl -e '@A=split(/:/,$ENV{PATH});%H=map {$A[$#A-$_]=>$#A-$_} (0..$#A);@A=join(":",sort{$H{$a} <=> $H{$b} }keys %H);print "@A"'`
export PATH
@dvliman
dvliman / gist:5533852
Created May 7, 2013 16:12
redis memory consumption for 1 million key value pairs
require 'rubygems'
require 'redis'
require 'faker'
r = Redis.new
(0..1000000).each do
name = Faker::Name.name
content = Faker::Lorem.sentence
puts "Name: #{name}, Content: #{content}"
r.set(name, content)
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
typedef unsigned int u32;
typedef unsigned long long u64;
//-------------------------------------------------------------------------
// WorkArea
//-------------------------------------------------------------------------
@dvliman
dvliman / Encbox.md
Created July 20, 2013 21:04 — forked from Tho85/Encbox.md

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
@dvliman
dvliman / gist:6066876
Created July 23, 2013 22:55
Angular.js Examples
@dvliman
dvliman / gist:6085535
Created July 26, 2013 02:15
recursively hit instagram API
2013/07/25 22:12:09 authorization code: d57837cc40344f438a36442ccd3c1aab
2013/07/25 22:12:10 access token: 23568145.222c75b.09b3dfca7d1c4dbc8ee0259a3b4ce41e
2013/07/25 22:12:10 full name: David Liman
2013/07/25 22:12:10 fetching: https://api.instagram.com/v1/users/self/media/liked?access_token=23568145.222c75b.09b3dfca7d1c4dbc8ee0259a3b4ce41e
2013/07/25 22:12:10 19
2013/07/25 22:12:10 fetching: https://api.instagram.com/v1/users/self/media/liked?access_token=23568145.222c75b.09b3dfca7d1c4dbc8ee0259a3b4ce41e&max_like_id=500237245337438317
2013/07/25 22:12:11 38
2013/07/25 22:12:11 fetching: https://api.instagram.com/v1/users/self/media/liked?access_token=23568145.222c75b.09b3dfca7d1c4dbc8ee0259a3b4ce41e&max_like_id=492781729775274735
2013/07/25 22:12:12 57
2013/07/25 22:12:12 fetching: https://api.instagram.com/v1/users/self/media/liked?access_token=23568145.222c75b.09b3dfca7d1c4dbc8ee0259a3b4ce41e&max_like_id=480496198771468554
package main
import "fmt"
func main() {
// #=> slice is pass by reference
test := []int{1, 2}
fmt.Println(test)
modify(test)
fmt.Println(test)