Skip to content

Instantly share code, notes, and snippets.

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"
)
@ewalk153
ewalk153 / fast_pg_restore.sh
Created July 24, 2014 21:06
Faster restore of postgres backup by ignoring certain data
pg_restore -l cr2.dump > db.list
# edit db.list
pg_restore --verbose --clean --no-acl --no-owner -h {HOST} -U {USER} -d {DATABASE} -L db.list cr2.dump
@ewalk153
ewalk153 / mini-bot.go
Last active August 29, 2015 14:04
Mini-bot is a mini hipchat bot that listens in a given room, and runs actions based on user interactions
package main
import (
"errors"
"fmt"
api "github.com/andybons/hipchat"
"github.com/daneharrigan/hipchat"
"github.com/joho/godotenv"
"os"
"strings"
@ewalk153
ewalk153 / mbox.go
Created August 18, 2014 22:19
parse MBOX file format for attachments
package main
import (
"bufio"
"bytes"
"encoding/base64"
"fmt"
"io"
"io/ioutil"
// "log"
@ewalk153
ewalk153 / ex_serial.rb
Created August 27, 2014 15:49
example to serialize an attribute in Ruby
class FavOptions < Array
def self.dump(ingredients)
ingredients ? ingredients.join(";") : nil
end
def self.load(ingredients)
ingredients ? new(ingredients.split(";")) : nil
end
end
@ewalk153
ewalk153 / pg_tablebackup.bash
Created August 28, 2014 11:52
backup one postgres tables as CSV, compressed
time psql DBNAME -F , --no-align -c "SELECT * FROM TABLE" | gzip -9 > table_backup.gz
@ewalk153
ewalk153 / rails-4-clean_guide.sh
Last active August 29, 2015 14:09
All queries should be empty! :). This can be run on a rails 3.2.x codebase to make sure ActiveRecords is prepared for rails 4. This does NOT handle rails4 methods that have no rails 3.2 counterpart.
# no find_all_by
grep -e "find_all_by" -r --include "*.rb" .
# no :conditions
grep -e ":conditions" -r --include "*.rb" .
# no naked scopes
grep -r -e "scope :" --include "*.rb" . | grep -v "lambda" | grep -v '\->'
# no naked default_scopes