Skip to content

Instantly share code, notes, and snippets.

View aantix's full-sized avatar

Jim Jones aantix

View GitHub Profile
@smsohan
smsohan / RubyAdvancedFeatures
Created November 12, 2010 05:50
Some advanced ruby features
#the new tap method of ruby will always return itself, but lets you play with!
data = (1..10).to_a
data.tap{|x| print x}.to_a.join(', ')
p
#alias will redirect method calls to method with a different name, useful for api changing
class SomeClass
def new_method(x)
p "The value is #{x}"
@aantix
aantix / seed_model_hash_dump.rb
Created January 1, 2011 02:34
Display model data in hash form for create -- Useful in dumping old Rails model data (for seeds.rb)
model = Object::const_get(ARGV[0])
rows = model.find(:all)
# Any columns you don't want output, list here as symbols
# e.g. BLACKLIST = [:user_id, :workout_id]
BLACKLIST = []
# Any columns that you'd like to rename on the output, list in this hash
# e.g. TRANSFORM = {:percentOfMax => :percent_of_max}
TRANSFORM = {}
@aantix
aantix / factories_from_db.rb
Created January 16, 2011 12:14
Takes a seeded model and dumps out the data in a format that can be used for testing factories
# 523 : ~/Projects/runfatboy2 $ rails runner ~/factories_from_db.rb Exercise 1 2 3
#
# Factory.define :exercise_incline press do |r|
# r.name 'Incline Press'
# r.url 'http://video.google.com/googleplayer.swf?docId=-5762262560903802111&hl=en'
# r.verb 'Lift'
# r.measurement_type_id 3
# r.exercise_type_id 1
# r.user_id 2
# r.start_weight 0.8
@aantix
aantix / sync.rb
Created January 19, 2011 21:38
RSyncs all svn changed files to a remote VM volume. Useful when you want to test changes on a remote VM, but not necessarily commit them to the SVN trunk.
#!/usr/bin/env ruby
ignore_patterns = ["db/","test","log","reports","server","vendor/","Gemfile","tmp",".idea","config/",".DS_Store", ".xml", '.zip']
ignore_statuses = ['!','D','?']
changed_files = (`svn status`).split("\n").collect do |e|
p = e.split(/\s+/)
ignore_statuses.include?(p[0]) ? nil : p[p.size - 1]
end.compact
@zefer
zefer / heroku_cedar_hirefire_patch.rb
Created July 14, 2011 15:28
Patch HireFire so worker auto-scaling works on the Beta Heroku Cedar stack
# hopefully a temporary patch so HireFire will run on the Heroku Cedar stack
# NB: the worker type is hard-coded as "worker" below, this must correlate to the type in Procfile
# NB: ENV['APP_NAME'] must be defined (e.g. 'heroku config:add APP_NAME=myherokuappname')
# using ps & ps_scale instead of info & set_workers
class HireFire::Environment::Heroku
private
def workers(amount = nil)
@wycats
wycats / marshal_proc.rb
Created November 19, 2011 06:11
Source code for marshaling a Proc in Rubinius. See http://yehudakatz.com/2011/11/19/how-to-marshal-procs-using-rubinius/ for more details
module Rubinius
class CompiledMethod
def _dump(depth)
Marshal.dump([@scope, Rubinius::CompiledFile::Marshal.new.marshal(self)])
end
def self._load(string)
scope, dump = Marshal.load(string)
cm = Rubinius::CompiledFile::Marshal.new.unmarshal(dump)
cm.scope = scope

Deploy Rails 4 app with Dokku on DigitalOcean

Install dokku

First create a Ubuntu 13.04 x64 droplet on DigitalOcean Control Panel

Then ssh with root account, run this in termianl:

$ wget -qO- https://raw.github.com/progrium/dokku/master/bootstrap.sh | sudo bash
@berg
berg / gist:9142463
Last active March 14, 2016 19:32
Comcast and Netflix now have a direct adjacency

Comcast and Netflix now have a direct adjacency

Looked at the host serving my Netflix streams today and noticed something new.

No clue if money is changing hands or not, and the return path is what actually matters, but it appears that Comcast and Netflix have reached some sort of agreement regarding direct interconnection.

$ traceroute -a 198.45.63.164
traceroute to 198.45.63.164 (198.45.63.164), 64 hops max, 52 byte packets
    (hops 1-2 redacted)
@francois-blanchard
francois-blanchard / config_server_with_chef_for_rails.md
Last active December 1, 2017 12:52
Build server with chef for deploy rails app

Configure server for deploy rails app

Objective

Prepare a server for a Rails app with MySQL (percona) + NGINX (passenger)
Deploy rails app in new server with Capistrano v3

For this example we need :

@francoisTemasys
francoisTemasys / installJitsiTMS.sh
Last active December 14, 2018 16:38
This script will deploy a jitsi.meet webserver (running on nginx) and a jitsi.videobridge XMPP component (running on Prosody). No TURN server is installed and no NAT server configuration is created.
#/bin/bash
#(c) Copyright 2014 Temasys Communication, Pte Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software