Skip to content

Instantly share code, notes, and snippets.

View jeremywrowe's full-sized avatar
❤️
Coding

Jeremy W. Rowe jeremywrowe

❤️
Coding
View GitHub Profile
@jeremywrowe
jeremywrowe / modules.rb
Created July 21, 2013 15:41
This is totally insecure and just a proof of concept. I find myself annoyed that parent modules have to exist prior to creating their children. Modules are a form of namespacing code and we should be able to organize that code however we want.
#!/usr/bin/env ruby
def create_module(representation, &block)
parts = representation.split("::")
(0...parts.size).each do |idx|
const = parts[(0..idx)].join("::")
eval "::#{const} = Module.new unless defined?(::#{const})"
end
if block_given?
require "ostruct"
class Bar
attr_reader :num
def initialize(num)
@num = num
end
def zoo
render json: Resource.where(something: params[:something]).first_or_create do |r|
r.enabled = params[:enabled]
r.foo = params[:foo]
r.bar = params[:bar]
end
#include <stdio.h>
int main(int argc, char* argv[]) {
int a = 1;
a++;
printf("%d\n", a);
}
# => 2
class Message
MAX_LENGTH = 240
...
end
migrate () {
local zeus_command=""
if _zeus-installed
then
zeus_command="zeus"
fi
$zeus_command rake db:migrate && $zeus_command rake db:rollback && $zeus_command rake db:migrate && $zeus_command rake db:test:prepare
}
@jeremywrowe
jeremywrowe / gist:5373873
Last active December 16, 2015 03:59
Do you want to get onto your recent branchies easy? Here - ya - go. Create a new file named whatever you want, make it executable and put it in your path. From there go to your favorite project that you are working on type in whatever you named the script, and you are off to the races.
#!/usr/bin/env ruby
trap("INT") { puts "\ncatch'ya later"; exit 0 }
output = `git for-each-ref --count=10 --sort=-committerdate refs/heads/ --format='%(refname:short)'`
branches = output.split("\n")
unless option = ARGV[0]
puts <<-MSG
@jeremywrowe
jeremywrowe / too_legit.c
Last active August 11, 2016 17:52
Bringing goto statements in c back into style.
#include <stdlib.h>
#include <stdio.h>
#define too goto
int main( int argc, const char* argv[]) {
int times;
times = 0;
legit:
printf(" too legit,");
@jeremywrowe
jeremywrowe / cucumber_leaks.rb
Last active December 15, 2015 20:41
Show leaked instance variables in cucumber. A terrible hack but sometimes that is what ya need to do :)
$cucumber_instance_variables = []
Before do
$cucumber_instance_variables = instance_variables
end
After do
test_variables = instance_variables - $cucumber_instance_variables
message = "[WARN] the following test variables could be leaking #{leaked_variables.join(', ')}"
@jeremywrowe
jeremywrowe / routs_rails_console.rb
Created April 5, 2013 14:37
routes in rails console
include ActionDispatch::Routing
include Rails.application.routes.url_helpers