Skip to content

Instantly share code, notes, and snippets.

View hayeah's full-sized avatar
🕳️
Focusing

blah blah hayeah

🕳️
Focusing
View GitHub Profile
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
$ () ->
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
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')
@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))
@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: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--){
a = (a / 2) - (b / 2)
c = / 2) - (b /
@hayeah
hayeah / gist:3925801
Created October 21, 2012 04:45
sample nginx rails config
server {
# server_name baolaika.com api.baolaika.com demo.baolaika.com;
server_name pfadmin.baolaika.com;
root /home/deploy/www/puffant-admin/current/public;
location ~ ^/assets/sdk {
access_log off;
gzip_static on;
}
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
typedef struct node{
int e;
struct node *next;
} node;
node *list_build(int* a,int size) {
@hayeah
hayeah / sidekiq.rb
Created April 30, 2013 18:50
Starting sidekiq worker process using zeus for faster testing
# adapted from bin/sidekiq
# to invoke, run: zeus runner sidekiq.rb
require 'sidekiq/cli'
begin
cli = Sidekiq::CLI.instance
cli.parse
cli.run
rescue => e