Skip to content

Instantly share code, notes, and snippets.

@ewalk153
ewalk153 / array_change.go
Created July 6, 2012 14:07
Change from []Struct to []Interface in go
package main
type Box interface {
Width() int
}
type Square struct {
w int
}
@ewalk153
ewalk153 / bufioEx.go
Created July 23, 2012 07:32
Bufio example
package main
import (
"bufio"
"fmt"
"os"
"time"
)
/* simple go app showing the use of a buffered writer */
@ewalk153
ewalk153 / woot.rb
Created April 8, 2013 16:39
Https example...
require 'net/http'
require 'net/https'
class Woot
def foo
uri = URI.parse("https://www.google.fr/?q=example")
https = Net::HTTP.new(uri.host,uri.port)
https.use_ssl = true
req = Net::HTTP::Get.new(uri.path)
res = https.request(req)
@ewalk153
ewalk153 / config.ru
Last active December 16, 2015 00:09
quick script to accept post data
require 'rubygems'
require './post'
run Sinatra::Application
@ewalk153
ewalk153 / networkTest.go
Last active December 17, 2015 13:10
Go script for testing your internet connection (by downloading an large file and verifying that it continues to download).
package main
import (
"fmt"
"io"
"net/http"
"os"
"time"
)
@ewalk153
ewalk153 / gotit.go
Created May 27, 2013 23:52
Simple web app to listen for incoming requests
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func handler(w http.ResponseWriter, r *http.Request) {
@ewalk153
ewalk153 / fix_perm.sh
Created June 3, 2013 09:11
Quick script to remove exec permissions on all files in a directory, recursively.
find . -type f -name "*.go" -exec chmod a-x {} +
@ewalk153
ewalk153 / pg_hrefresh.sh
Created July 23, 2013 19:14
heroku and postgres script to restore from the latest backup
#!/bin/sh
DIR="$(basename $(PWD))"
DIR="${DIR/-/_}"
if [ "$1" == "execute" ]
then
if [ ! -f 'dump.db' ]
then
echo "downloading backup"
curl `heroku pgbackups:url` > dump.db
@ewalk153
ewalk153 / phones.rb
Created September 13, 2013 09:20
Format and standardize parsing of phone numbers in our projects with this
def parse_phone(string)
(Phoner::Phone.parse(string) || Phoner::Phone.parse('+' + string) rescue 'failed')
end
def verify_phones
CSV.generate do |csv|
Trip.all.each do |t|
csv << [t.mobile, parse_phone(t.mobile)]
end
end
@ewalk153
ewalk153 / des3.rb
Created September 17, 2013 16:07
Basic example script for encrypting/decrypting with 3DES.
require 'openssl'
require 'base64'
# Generate with this: OpenSSL::Cipher::Cipher.new("des-ede-cbc").tap{|c| c.encrypt}.random_key
key = "\xBEB\xBA;\xA5\xEA-\x1A4\x0E8\xAC\x13\xF1s9\xB2\x87\xD3D\x9A\xC2\xA8\xC7"
def encrypt(message, key)
des_cbc=OpenSSL::Cipher::Cipher.new("des-ede-cbc")
des_cbc.encrypt