Skip to content

Instantly share code, notes, and snippets.

View dpaluy's full-sized avatar

David Paluy dpaluy

  • Majestic Labs
  • Austin, TX
  • X @dpaluy
View GitHub Profile
def memstats
size = `ps -o size= #{$$}`.strip.to_i
end
@dpaluy
dpaluy / changelog_diff
Created October 6, 2013 16:04
Get changelogs for all gems included in a Rails project
#!/usr/bin/env ruby
class GemDetails
attr_accessor :name, :version, :changelog_file
def initialize(name, version)
@name, @version = name, version
end
def self.from_str(str)
@dpaluy
dpaluy / gofindxss.js
Last active December 27, 2015 23:09
var http = require('follow-redirects').http;
//top 1000
var domains = ["google.com","facebook.com","youtube.com","yahoo.com","baidu.com","wikipedia.org","qq.com","linkedin.com","live.com","twitter.com","amazon.com","blogspot.com","taobao.com","google.co.in","sina.com.cn","wordpress.com","yahoo.co.jp","yandex.ru","bing.com","ebay.com","google.de","vk.com","hao123.com","163.com","tumblr.com","pinterest.com","google.co.uk","google.fr","googleusercontent.com","microsoft.com","msn.com","ask.com","mail.ru","google.co.jp","google.com.br","weibo.com","apple.com","paypal.com","google.ru","instagram.com","google.com.hk","xvideos.com","blogger.com","google.it","tmall.com","google.es","imdb.com","soso.com","craigslist.org","sohu.com","360.cn","go.com","amazon.co.jp","stackoverflow.com","bbc.co.uk","xhamster.com","google.com.mx","neobux.com","google.ca","fc2.com","cnn.com","imgur.com","alibaba.com","wordpress.org","flickr.com","espn.go.com","adcash.com","huffingtonpost.com","odnoklassniki.ru","t.co","conduit.com","thepira
# config/initializers/postgresql_patch.rb
#
class ActiveRecord::ConnectionAdapters::AbstractAdapter
def translate_exception(exception, message)
if exception.is_a?(PG::InvalidTextRepresentation)
raise ActiveRecord::RecordNotFound
else
# override in derived class
ActiveRecord::StatementInvalid.new(message, exception)
end
@dpaluy
dpaluy / aws_policy.js
Created November 15, 2014 21:49
AWS Policy signature example
function sign(req, res, next) {
var fileName = req.body.fileName,
expiration = new Date(new Date().getTime() + 1000 * 60 * 5).toISOString();
var policy =
{ "expiration": expiration,
"conditions": [
{"bucket": bucket},
{"key": fileName},
@dpaluy
dpaluy / dangerous.rake
Last active April 4, 2017 20:54
Disable dangerous rake tasks in production
DISABLED_TASKS = [
'db:drop',
'db:migrate:reset',
'db:schema:load',
'db:seed',
# ...
]
namespace :db do
desc "Disable a task in production environment"
RUBY_GC_HEAP_FREE_SLOTS=4096 # Must be > 0
RUBY_GC_HEAP_INIT_SLOTS=10000 # Must be > 0
RUBY_GC_HEAP_GROWTH_FACTOR=1.8 # Must be > 1.0
RUBY_GC_HEAP_GROWTH_MAX_SLOTS=0 # Disabled; Must be > 0
RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=2.0 # Must be > 0
RUBY_GC_MALLOC_LIMIT=16777216 # 16 MiB; Must be > 0
RUBY_GC_MALLOC_LIMIT_MAX=33554432 # 32 MiB; Must be > 0
RUBY_GC_MALLOC_LIMIT_GROWTH_FACTOR=1.4 # Must be > 1.0
RUBY_GC_OLDMALLOC_LIMIT=16777216 # 16 MiB; Must be > 0
RUBY_GC_OLDMALLOC_LIMIT_MAX=134217728 # 128 MiB; Must be > 0
require "net/http"
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
XRUBY_GC_HEAP_FREE_SLOTS=4096
XRUBY_GC_HEAP_INIT_SLOTS=10000
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0
@dpaluy
dpaluy / setup.sh
Last active August 29, 2015 14:23
Mac brew tools
#you need to get new ctags, i recommend homebrew but anything will work
brew install ctags
#alias ctags if you used homebrew
alias ctags="`brew --prefix`/bin/ctags"
xcode-select --install
brew install macvim --override-system-vim
brew install git
@dpaluy
dpaluy / toc.rb
Created July 4, 2015 08:55
Generate Table of Contents for Markdown files
#!/usr/bin/env ruby
File.open("Readme.md", 'r') do |f|
f.each_line do |line|
forbidden_words = ['Table of contents', 'define', 'pragma']
next if !line.start_with?("#") || forbidden_words.any? { |w| line =~ /#{w}/ }
title = line.gsub("#", "").strip
href = title.gsub(" ", "-").downcase
puts " " * (line.count("#")-1) + "* [#{title}](\##{href})"