Skip to content

Instantly share code, notes, and snippets.

View ljsc's full-sized avatar

Lou Scoras ljsc

  • Bloomberg LP
  • Washington, DC
View GitHub Profile
module TimeMethods
def self.define_time(sym, secs)
module_eval <<-EOC, __FILE__, __LINE__
def #{sym}; self * #{secs} end
alias_method :#{sym}s, :#{sym}
EOC
end
Numeric.send(:include, self)
CmdUtils.CreateCommand({
name: "github",
description: "Searchs Github for a code repository",
icon: "http://github.com/favicon.ico",
author: { name: "Louis J. Scoras", email: "[email protected]"},
license: "MPL,GPL",
takes: { "search string": noun_arb_text },
templates: {
preview_header: function(q) {
@ljsc
ljsc / snippet.rb
Created November 20, 2008 21:18 — forked from anonymous/snippet.rb
require 'date'
module DateDiff
module_function
def difference_in_months(d1, d2)
DateDifference.new(d1,d2).months
end
class DateDifference
@ljsc
ljsc / quiz.rb
Created May 15, 2009 18:57 — forked from ryanb/quiz.rb
# COMMUNITY CHALLENGE
#
# Here's my (@ljsc) solution. I guess this would qualifiy as a mock.
#
class Quiz
def initialize(input = STDIN, output = STDOUT)
@input = input
@output = output
end
require 'pp'
class Foo
def parameterfest(one, two, subopts, opts)
puts "One: #{one}"
puts "Two: #{two}"
puts "Subopts: #{subopts.pretty_print_inspect}"
puts "Opts: #{opts.pretty_print_inspect}"
end
end
(x:xs) `minus` yys@(y:ys)
| x == y = xs `minus` ys
| otherwise = x : xs `minus` yys
naturals = [1..]
evens = [2,4..]
odds = naturals `minus` evens
{-
@ljsc
ljsc / punch_nil_in_the_face.rb
Created August 6, 2011 14:15
Dancing around nils
get_membership(:user => user) do |m|
m.one {|m| do_something_with_one_membership(m) }
m.none { oops_no_membership() }
end
@ljsc
ljsc / gist:1213998
Created September 13, 2011 14:54
Autoplay and loop youtube video
(function(){var l=window.location,u='http://youtube.com/v/'+/v=([A-Za-z0-9][^&]*)(?:&|$)/.exec(l.search)[1]+'?loop=1&autoplay=1';l.replace(u);})();
@ljsc
ljsc / .gitconfig
Created February 10, 2012 03:57
Custom git log format
[alias]
ls = log --graph --color --pretty=\"format:%C(yellow)%h%Creset%C(green)%d%Creset %s %Cblue[%aN]%Creset %C(magenta){%cr}%Creset\"
@ljsc
ljsc / gist:5816855
Last active December 18, 2015 17:09 — forked from richmolj/gist:5811358
Add factory method.
class Post
# Make the DI overhead a bit more bareable with a factory method. You can
# still use the default constructor if you need the extra flexibility.
#
# I'm not quite sure about this last parameter though for the should_order.
# Most of the time passing a boolean is a code smell that you have some unwanted
# control coupling...
#
def self.standard_post(should_order)
alarm_handler = AlarmHandler.new(:post_search)