Skip to content

Instantly share code, notes, and snippets.

@kavu
kavu / main.go
Created July 6, 2013 08:52
Setting Process name in Go
func SetProcessName(name string) error {
argv0str := (*reflect.StringHeader)(unsafe.Pointer(&os.Args[0]))
argv0 := (*[1 << 30]byte)(unsafe.Pointer(argv0str.Data))[:argv0str.Len]
n := copy(argv0, name)
if n < len(argv0) {
argv0[n] = 0
}
// Syscall PRCTL, not working on Darwin for me
@kavu
kavu / Vagrantfile
Last active December 15, 2015 05:59
Vagrant::Config.run do |config|
# ssh settings:
config.ssh.private_key_path = "~/.ssh/vagrant.key"
config.ssh.max_tries = 5
config.ssh.timeout = 10
# default port forwarding
config.vm.forward_port('ssh', 22, 2222, :auto => true)
@kavu
kavu / main.go
Created March 20, 2013 13:52
Go Reflection
func(t reflect.Type) {
log.Printf("%+v", t.Field(0).Tag.Get("woot"))
}(reflect.TypeOf(Dummy{1}))
@kavu
kavu / main.go
Created March 20, 2013 13:50
Go Mem and CPU Profiles
file, err := os.Create("go.cprof")
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(file)
// ...
pprof.StopCPUProfile()
@kavu
kavu / git-cleanup.sh
Last active December 14, 2015 15:28
This is how you can delete some HUGE dir in your repo's history. Warning! Make a backup and don't try it, if you don't understand what are you doing!
# Let's figure out what we have in the beggning
git fsck --full --strict --unreachable
git count-objects -v
# Filter ALL branches deleteing `db/seeds_assets`
git filter-branch -f --tree-filter 'rm -rf db/seeds_assets' -- --all
# Remove original reflogs
rm -rf .git/refs/original/
build_package_combined_patch() {
local package_name="$1"
{
curl https://github.com/funny-falcon/ruby/compare/p385...p385_falcon.diff | patch -p1
autoconf
./configure --prefix="$PREFIX_PATH" $CONFIGURE_OPTS
make -j 8
make install
} >&4 2>&1
}
@kavu
kavu / 1.rb
Last active December 12, 2015 01:28
require 'minitest/autorun'
class MyClass
def initialize
@a = 1
end
def a
"not a 1"
end
@kavu
kavu / attr_scanner.rb
Created January 3, 2013 16:05
attr_scanner.rb by@joernchen
#!/usr/bin/env ruby
#
# Mass assignment scanner for Ruby on Rails
# should be run from rails console in production
# environment.
#make sure all models are loaded
Dir[Rails.root + 'app/models/**/*.rb'].each { |path| require path }
models = ActiveRecord::Base.subclasses
@kavu
kavu / deploy.rb
Created November 8, 2012 14:20 — forked from mertonium/deploy.rb
Capistrano task to notify Ratchet.io about deployment
# I am trying out Ratchet.io and I want to add their deployment notification to my
# normal capistrano deployment process. Here is my first working attempt.
# Add this task to your deploy.rb
task :notify_ratchetio, :roles => :app do
set :revision, `git log -n 1 --pretty=format:"%H"`
set :local_user, `whoami`
set :ratchetio_token, YOUR_ACCESS_TOKEN
rails_env = fetch(:rails_env, "production")
run "curl https://submit.ratchet.io/api/1/deploy/ -F access_token=#{ratchetio_token} -F environment=#{rails_env} -F revision=#{revision} -F local_username=#{local_user} >/dev/null 2>&1"
@kavu
kavu / 1.9.3-p327-perf
Created October 31, 2012 09:37
RBenv — Ruby 1.9.3 with the latest @funny-falcon perf patch
build_package_combined_patch() {
local package_name="$1"
{
curl https://raw.github.com/gist/4136373/falcon.diff | patch -p1
autoconf
./configure --prefix="$PREFIX_PATH" $CONFIGURE_OPTS
make -j 8
make install
} >&4 2>&1
}