Skip to content

Instantly share code, notes, and snippets.

View j4zzcat's full-sized avatar

Sharon Dagan j4zzcat

View GitHub Profile
file utils.rb:
--------------
require 'webrick'
module Utils
WEBrick::HTTPStatus::StatusMessage.each do | k, v |
self.const_set "HTTP_#{k}_#{v.upcase.tr ' -', '_'}".to_sym, k
end
end
#! /bin/bash
# Create a temp file
program=$(mktemp /tmp/XXXX)
# Get the line number of the last match of __PROGRAM_START__
# Just grep-ing the file to find the marker will match the grep itself
cut_pos=$(cat ${0} | grep -n '__PROGRAM_START__' | tail -1 | awk -F ':' '{print $1}')
# Get the docker image tag to run the program in
TOPLEVEL_BINDING.eval( 'def task( *args, &block ); end' )
load 'Rakefile'
require 'rake'
rakefile = 'some-rake-file'
rake = Rake.application
rake.init
rake.add_import rakefile
rake.load_rakefile
rake[ :taskname ].invoke
load GEMSPEC_FILE
ObjectSpace.each_object Gem::Specification do | instance |
if instance.name == GEMSPEC_FILE
gemspec = instance
break
end
end
@j4zzcat
j4zzcat / rack-rest-api-example.rb
Created January 2, 2017 11:24 — forked from peter/rack-rest-api-example.rb
An example of how to write a simple JSON REST API with a simplistic router directly on top of Rack (i.e. without the use of a framework like Sinatra).
#################################################################
#
# File: lib/api.rb
#
#################################################################
require 'user' # ActiveRecord model
# Connect to the db
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])