Skip to content

Instantly share code, notes, and snippets.

@ndbroadbent
ndbroadbent / deploy.rake
Created September 28, 2012 22:18
Rake task for precompiling assets locally before deploying to Heroku
require 'fileutils'
# Warning: The following deploy task will completely overwrite whatever is currently deployed to Heroku.
# The deploy branch is rebased onto master, so the push needs to be forced.
desc "Deploy app to Heroku after precompiling assets"
task :deploy do
deploy_branch = 'heroku'
remote = 'heroku'
deploy_repo_dir = "tmp/heroku_deploy"
@stympy
stympy / url_checker.rb
Last active May 2, 2021 19:45
Ruby class to check URL validity
require "ipaddr"
require "resolv"
require "uri"
class UrlChecker
SCHEME_REGEX = Regexp.new(/\Ahttps?/)
HOST_REGEX = Regexp.new(/.+\..+/)
IPV4_REGEX = Regexp.new(/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/)
IPV6_REGEX = Regexp.new(/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/)
PRIVATE_RANGES = %w[127.0.0.0/8 192.168.0.0/16 172.16.0.0/12 10.0.0.0/8 100.64
@mikhailov
mikhailov / ruby_gc.sh
Created March 11, 2011 10:33
Ruby’s GC Configuration
- http://www.coffeepowered.net/2009/06/13/fine-tuning-your-garbage-collector/
- http://snaprails.tumblr.com/post/241746095/rubys-gc-configuration
article’s settings: ("spec spec" took 17-23!sec)
export RUBY_HEAP_MIN_SLOTS=1250000
export RUBY_HEAP_SLOTS_INCREMENT=100000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=30000000
export RUBY_HEAP_FREE_MIN=12500
@joho
joho / deploy.rb
Created September 13, 2012 01:30
How to serve emergency "signed out" views from page cache without affecting signed in users in rails.
set :path_to_repo, "/path_to_repo/"
set :running_app_user, "appusername"
namespace :webscale do
desc "Cache a signed out version of the path. Usage: cap webscale:signed_out_cache_page -s path_to_cache=/films/on_netflix"
task :signed_out_cache, roles: :app do
cache_base_path = "#{path_to_repo}/public/signed_out"
cached_destination_path = "#{cache_base_path}#{path_to_cache}.html"
working_path = "#{cached_destination_path}.tmp"
@rweald
rweald / simple-linear-regression.rb
Created August 29, 2012 19:13
Simple Linear Regression in Ruby
class SimpleLinearRegression
def initialize(xs, ys)
@xs, @ys = xs, ys
if @xs.length != @ys.length
raise "Unbalanced data. xs need to be same length as ys"
end
end
def y_intercept
mean(@ys) - (slope * mean(@xs))
@kitop
kitop / script.sh
Created March 31, 2017 07:39
Template Bash Script
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
# Taken from https://dev.to/thiht/shell-scripts-matter
#/ Usage:
#/ Description:
#/ Examples:
#/ Options:
@nu7hatch
nu7hatch / _utils.bash
Created April 15, 2013 04:44
Utilities for setup scripts.
# _utils.sh --- Utilities used across all the scripts.
set -e
set -o pipefail
# Prints spaces as a prefix to the command's output.
function prefixed {
sed -e "s/^/ /"
}
@djanowski
djanowski / gist:3750231
Created September 19, 2012 15:22
Why I don't use...

Why I don't use...

I'm numbering my arguments just to be able to reference them. Order does not reflect priority.

jQuery

  1. It's monolithic.

  2. It's huge, both in terms of complexity and in resulting file size.

@mrrooijen
mrrooijen / .gitignore
Created February 1, 2012 18:04
MiddleMan on Heroku configuration.
.DS_Store
*.swp
*.swo
Gemfile.lock