Skip to content

Instantly share code, notes, and snippets.

View mattetti's full-sized avatar

Matt Aimonetti mattetti

View GitHub Profile
# Installation
# ============
# Installation of Ubuntu Server is automated by
# 'preseeding' configuration options with the values expected for vagrant.
# Clock and Timezone
# ------------------
# ### Hardware Clock
@mattetti
mattetti / main.go
Created January 6, 2014 01:59
Static web server in Go that can be cross compiled for Windows, Linux, Mac etc.. Content available in the public folder will be served automatically.
package main
import (
"log"
"net/http"
)
func main() {
http.Handle("/", http.FileServer(http.Dir("public")))
log.Println("About to start the server on port 8014")
@mattetti
mattetti / rails_encryptor_reduction.rb
Last active December 29, 2015 16:28
Quick high level rundown showing how Rails 4 sets the message encryptor used for sessions, signed messages and more.
require "active_support"
require "active_support/key_generator"
require "json"
# Based on https://gist.github.com/mattetti/7624413
module JsonSessionSerializer
def self.load(value)
begin
JSON.parse(value)
rescue JSON::ParserError
@mattetti
mattetti / rails_json_session.rb
Last active September 23, 2020 07:04
This is a monkey patch to change Rails 4's default session/signed cookie serializer from Marshal to JSON for security and compatibility reasons. Note that this is a hack, a pretty terrible one and you should only use it if you know what you're doing. Also, I only wrote this patch for my own personal use, so don't be surprised if it doesn't work …
# Hack to change the Rails cookie serializer from Marshal to JSON and therefore allow the session
# to be shared between different languages but also avoid that someone knowing the
# cookie secret key could execute arbitrary code on the server by unmarshalling
# modified Ruby code added to the session/permanent cookie.
#
# Note that all users will beed to login again since both the remember me cookie and the session cookies
# won't be valid. Note also that the remember me cookie is tested multiple times per request even when it fails.
# for performance reasons you might want to delete it if these extra cycles are too costly for you.
#
# Rails 4 (not tested on Rails 3).
$ go test -cover fmt
# testmain
/var/folders/cw/ybbv7rqj16b5jxr5k69zq7xw0000gn/T/go-build683876954/fmt/_test/_testmain.go:142: undefined: testing.CoverBlock
/var/folders/cw/ybbv7rqj16b5jxr5k69zq7xw0000gn/T/go-build683876954/fmt/_test/_testmain.go:168: undefined: testing.CoverBlock
/var/folders/cw/ybbv7rqj16b5jxr5k69zq7xw0000gn/T/go-build683876954/fmt/_test/_testmain.go:170: undefined: testing.CoverBlock
/var/folders/cw/ybbv7rqj16b5jxr5k69zq7xw0000gn/T/go-build683876954/fmt/_test/_testmain.go:184: undefined: testing.RegisterCover
/var/folders/cw/ybbv7rqj16b5jxr5k69zq7xw0000gn/T/go-build683876954/fmt/_test/_testmain.go:184: undefined: testing.Cover
FAIL fmt [build failed]
package main
// import whatever is needed
// define the types
// skipped for this example
func main() {
var count int
err := Db.Query(`SELECT count(id) FROM stuff`).Rows(&count)
gems = []
`bundle list`.split("\n").each do |line|
gem = line[/\*\s(.*)\s\(/, 1]
gems << gem
end
`bundle exec ruby -e "puts Gem.path"`.split("\n").each do |path|
gems.each do |gem|
licenses = Dir.glob("#{path}/gems/#{gem}*/LICEN*")
if licenses.empty?
package models
import (
"bitbucket.org/splice/splice_go/splice/logger"
"time"
)
type DbTime struct {
String string
Time time.Time
// To run this code, start create a MySQL DB named "jet-mysql-repro"
// and edit the setupDB variables to use the right connection settings.
package main
import (
"fmt"
"github.com/eaigner/jet"
_ "github.com/go-sql-driver/mysql"
"log"
"time"
@mattetti
mattetti / gist:6135091
Created August 1, 2013 20:42
Rakefile I use to crosscompile my golang app. Setup your machine for cross compilation first: http://dave.cheney.net/2012/09/08/an-introduction-to-cross-compilation-with-go
Signal.trap("SIGINT"){ puts " Ciao!"; exit }
task :default => :test
desc "Compile the app"
task :compile do
run_cmd "go build -ldflags \"-X main.Build #{short_sha1}\" <replace with path to app>"
end
desc "Cross compile the app and dump the binaries in the binaries submodule"