Skip to content

Instantly share code, notes, and snippets.

View hayeah's full-sized avatar
🕳️
Focusing

blah blah hayeah

🕳️
Focusing
View GitHub Profile
@hayeah
hayeah / gist:2593471
Created May 4, 2012 09:08
jquery ui patch to allow draggable element that is larger than container
drag: function(event, ui) {
var inst = $(this).data("draggable"), o = inst.options;
var d = o.snapTolerance;
var x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width,
y1 = ui.offset.top, y2 = y1 + inst.helperProportions.height;
for (var i = inst.snapElements.length - 1; i >= 0; i--){
@hayeah
hayeah / gist:2420034
Created April 19, 2012 09:53
yay for functional programming
auto_minimize: () ->
@_auto_minimize ||= _.debounce (=> this.minimize()), 4000
@_auto_minimize()
@hayeah
hayeah / gist:1319949
Created October 27, 2011 15:50
Emacs Lisp For The Fail
(defun ruby-reindent-then-newline-and-indent ()
(interactive "*")
(let* ((cur (point))
;; we need to insert a space artificially for this test to work properly :(
(expand-p (progn (insert " ")
(ruby-electric-space-can-be-expanded-p))))
;; remove the inserted space
(progn (goto-char cur)
(delete-char 1))
def print
@doc = Document.find(params[:id])
respond_to do |format|
format.html {
render "final", :layout => "print"
}
format.pdf {
html = render_to_string "final", :layout => "print"
p [:output,html]
kit = PDFKit.new(html, :page_size => 'Letter')
$ () ->
window.search = new LiveSearch("#search")
class LiveSearch
constructor: (context,result) ->
el = @context = $(context)
@result = el.find(".result")
@form = el.find("form")
@form.bind "ajax:success", (e,data) =>
window.data = data
module DealsHelper
def slider(klass,attr,opts={})
options = {
:max => max=klass.maximum(attr),
:min => min=klass.minimum(attr),
:range => true,
:values => [min,max]
}.merge(opts).to_json
input = hidden_field_tag "#{klass.to_s.underscore}[#{attr}]"
raw <<-HTML
<form action="#{search_path}" data-remote="true" data-type="html">
<div class='section'>
<h2>Dollar Amount Required</h2>
<%= slider(Deal,:dollar_amount_required,:format => "million",:step => 500_000) %>
</div>
<div class='section'>
<h2>Expected IRR</h2>
<%= slider(Deal,:expected_irr,:format => "percent",:step => 50) %>
</div>
module Abbrev
# Given a set of strings, calculate the set of unambiguous
# abbreviations for those strings, and return a hash where the keys
# are all the possible abbreviations and the values are the full
# strings. Thus, given input of "car" and "cone", the keys pointing
# to "car" would be "ca" and "car", while those pointing to "cone"
# would be "co", "con", and "cone".
#
flet do
def fact(i)
return 1 if i == 1
i * fact(i-1)
end
def fib(i)
return 1 if i == 0
return 1 if i == 1
fib(i-1) + fib(i-2)
require 'rubygems'
require 'rdiscount'
require 'nokogiri'
$blog = [:blog,
[[:timestamps, "2009-03-17T16:04:34-07:00"],
[:title, "Does Ruby Dream An Eclectic Shell?"],
[:categories, "hack"]],
[[:md,
[],