Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / bash.sh
Last active December 26, 2015 17:39
simplest web server testing
while true ; do nc -l 8080 < index.html ; done
@ewalk153
ewalk153 / Guardfile
Last active January 1, 2016 01:29
Go guard file. Slightly more advanced version.
require 'guard'
require 'guard/plugin'
class Guard::Mygo < Guard::Plugin
def run_all
system 'go test ./...'
end
def run_on_changes(paths)
paths.each do |file|
@ewalk153
ewalk153 / xml.go
Created December 25, 2013 17:56
go example for using XML
package main
import (
"encoding/xml"
"fmt"
"log"
)
type Reading struct {
RType string `xml:"r_type,attr"`
@ewalk153
ewalk153 / upgrade_postgres.bash
Created January 3, 2014 03:32
upgrade heroku postgres from crane to yanari
# this can be done anytime
heroku addons:add heroku-postgresql:standard-yanari --app nav-chronos; heroku pg:wait
# about 3m30s
heroku maintenance:on
heroku ps:scale worker=0
heroku pgbackups:capture --expire
# less than 20 min
cat | ruby -e "STDIN.readlines.select{|l|l[/memory_total/]}.map{|l| l.split(/\s+/)}.map{|l| puts \"#{l[2][/T[\d+:]+/][1..-1]} #{l[9][/([\d.]+)MB/][0..-3]}\"}"
@ewalk153
ewalk153 / pointer_only.go
Created April 18, 2014 13:17
Demonstrate that the SetYAML method only works with pointer Fields
package main
import (
"fmt"
"gopkg.in/yaml.v1"
"time"
)
type timeUnMarsh struct {
time.Time
@ewalk153
ewalk153 / mailhook.go
Created April 29, 2014 15:38
Record requests and display results, in memory
package main
import (
"fmt"
"net/http"
"os"
"strings"
)
//History of recent posts
package main
import (
"bytes"
"fmt"
"github.com/gorilla/sessions"
"html/template"
"net/http"
"strconv"
)