Skip to content

Instantly share code, notes, and snippets.

@jsvnm
jsvnm / copything.rb
Created November 17, 2011 16:02
from singleton to instance method
class Class
def method_to_instance(*names)
names.each{|name|
meth = method(name)
self.send(:define_method, name, meth.to_proc)
}
end
end
@jsvnm
jsvnm / opchain.rb
Created November 18, 2011 22:49
chained operators
#http://timelessrepo.com/chained-comparisons
[:<, :>, :<=, :>=].each do |operator|
[Float, Fixnum, Comparable].each do |klass|
klass.class_eval {
alias_method("__#{operator}__", operator)
define_method(operator) do |operand|
send("__#{operator}__", operand) and operand
end
}
@jsvnm
jsvnm / gist:1378718
Created November 19, 2011 10:57
animated text shadow
// from http://maettig.com/code/css/text-shadow.html
var handle = false;
var textBrightness = 50;
var fireCount = 6;
var fireDelta = new Array();
var step = 0;
var angle = 0;
var radius = 6;
function animate()
@jsvnm
jsvnm / infrubystuff.el
Created November 24, 2011 08:24
making pry work with inf-ruby
(add-to-list 'inf-ruby-implementations '("pry" . "pry"))
(setq inf-ruby-default-implementation "pry")
(setq inf-ruby-first-prompt-pattern "^\\[[0-9]+\\] pry\\((.*)\\)> *")
(setq inf-ruby-prompt-pattern "^\\[[0-9]+\\] pry\\((.*)\\)[>*\"'] *")
@jsvnm
jsvnm / some-misc-fns.el
Created November 24, 2011 12:49
exec/load -path searching and finding libraries
(defun exec-path-search (regexp)
(flatten (remove-if-not 'identity
(mapcar (lambda (dir) (directory-files dir t regexp))
exec-path))))
(defun load-path-search (&optional regexp full-path)
(unless regexp (set 'regexp "elc?$"))
(uniq (sort (flatten
(remove-if-not 'identity
(mapcar (lambda (dir) (directory-files dir full-path regexp)) load-path)))
@jsvnm
jsvnm / newfoldername
Created November 30, 2011 14:41
windows godmode
new folder on desktop, named:
GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}
@jsvnm
jsvnm / A_Z_cycle.cs
Created February 29, 2012 14:10
get next value in A..Z range using two lambdas, one Func<char> variable
static public class A_Z_cycle
{
static public Func<char> Next = () => {
const char a='A', b='Z', c=(char)(b-a+1);
int n=-1;
return (Next=(()=>(char)(a + (n=(n+1)%c))))();
};
}
@jsvnm
jsvnm / generation.cs
Created February 29, 2012 16:53
funcs that generate funcs that generate values. and things yield returning as enumerables
static public class FunFactory
{
static public Func<TResult> Make<TResult>(TResult a, Func<TResult, TResult> step)
{
TResult next=a;
return ()=>{ TResult cur=next; next=step(cur); return cur; };
}
static public Func<TResult> Cycle<TResult>(IEnumerable<TResult> values)
{
@jsvnm
jsvnm / ymd.rb
Created March 18, 2012 08:24
monkeypatch to Date to get difference to other date asstring with any or all of years,months,weeks,days. started out as codegolf...
class Date
# prev_week and next_week, add/remove 7 days * optarg
['prev_','next_'].each{|n|define_method(n+'week'){|w=1|send n+'day',7*w}}
# other is Date to compare to
# wants tells what to include in timediff. default is years,months,weeks,days
# by default returns <timediff> from <earlier> to <later>
# if abs=true returns <self> is <timediff> later|earlier than <other>
def diff_str other, want="ymwd",abs=false
return "Both dates are #{self}" if self==other
@jsvnm
jsvnm / gist:3544998
Created August 30, 2012 23:30
wanted "most recent before current"-window. get-mru-window gives current. instead of simplest, i did the most complex thing that could work. almost.
(defun windows-in-use-time-order (&optional old-to-new windows)
"Windows sorted by their `window-use-time'.
Without arguments windows on current frame ordered from most to least recent.
Optional argument OLD-TO-NEW with non-nil value reverses the order.
Optional argument WINDOWS specifies which windows to sort by use time:
- a list is assumed to contain windows and sorted