Skip to content

Instantly share code, notes, and snippets.

@ewalk153
ewalk153 / bash.sh
Last active December 26, 2015 17:39
simplest web server testing
while true ; do nc -l 8080 < index.html ; done
@ewalk153
ewalk153 / search_port.bash
Created October 7, 2013 10:08
find a machine with a given port open
for i in {10..254}; do nc -v -n -z -w 1 192.168.36.$i 8000; done
@ewalk153
ewalk153 / remove_rails_rc1.sh
Last active December 24, 2015 09:18
Remove all gems matching a certain version number with a shell script
# simple bash script that unstalls a version of rails (this could break if you have other gems matching the exact version name)
# here we remove rails 4.0.0.rc1
# v1, simple
#gem list | grep 4.0.0.rc1 | awk -F= 'BEGIN {FS = " "} ; {print $1}' | while read x ; do gem uninstall $x -v 4.0.0.rc1 ; done
# v2, even shorter, no need for awk
gem list | grep 4.0.0.rc1 | while read name _; do gem uninstall $name -v 4.0.0.rc1 ; done
@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
@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 / 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 / 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 / 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 / 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 / config.ru
Last active December 16, 2015 00:09
quick script to accept post data
require 'rubygems'
require './post'
run Sinatra::Application