Skip to content

Instantly share code, notes, and snippets.

View caryfitzhugh's full-sized avatar

Cary FitzHugh caryfitzhugh

View GitHub Profile
@caryfitzhugh
caryfitzhugh / gist:1287079
Created October 14, 2011 13:21
Pseudo Code For Redis Weighted Sorts
if (fieldlen > 0 ) {
if (o->type != REDIS_HASH || fieldname.len < 1) return NULL;
// Here is my new code inserted
// There is probably a better way to test for the []..
if (fieldname.buf[0] == '[' && fieldname.buf[fieldname.len] == ']') {
// First - do I need to do something with the refCount on the o above?
decrRefCount(o);
// Then I need to somehow create an robj with REDIS_ENCODING_INT
@caryfitzhugh
caryfitzhugh / gist:1595616
Created January 11, 2012 16:58
How to *really* do what I wanted in jquery
// I'm a dork of sorts, and like to make my xhr requests mime type .js in rails.
// It makes action files really easy to separate (.js files are for xhr, .html files are for html)
//
// I guess it could cause issues - maybe we should be creating an XHR/html mime type
// Regardless, it's what we do at my company... I guess b/c I wrote it.
//
// So that .js view file should return HTML. You can always execute the html if you need:
// <script> alert('this xhr response has JS!'); </script>
//
// Whereas you can't really do HTML inside JS very well.
@caryfitzhugh
caryfitzhugh / RaphaelJSShapeDrawingApp.html
Created March 11, 2012 02:37 — forked from kaylarose/RaphaelJSShapeDrawingApp.html
A Simple Vector Shape Drawing App with RaphaelJS and jQuery
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script src="http://yandex.st/raphael/1.5.2/raphael.min.js"></script>
<script>
/**
* A Simple Vector Shape Drawing App with RaphaelJS and jQuery
* copyright 2010 Kayla Rose Martin - Licensed under the MIT license
* Inspired by http://stackoverflow.com/questions/3582344/draw-a-connection-line-in-raphaeljs
**/
@caryfitzhugh
caryfitzhugh / gist:2015072
Created March 11, 2012 04:46
Simple Proof Of Concept For SVG image annotation in browser
<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://github.com/DmitryBaranovskiy/raphael/raw/master/raphael-min.js"></script>
<script>
/**
* A Simple Vector Shape Drawing App with RaphaelJS and jQuery
* copyright 2010 Kayla Rose Martin - Licensed under the MIT license
* Inspired by http://stackoverflow.com/questions/3582344/draw-a-connection-line-in-raphaeljs
**/
@caryfitzhugh
caryfitzhugh / gist:2641199
Created May 9, 2012 02:01
Inputs and outputs
Inputs:
{
"foo" => [{ start: 1, end: 10}],
"bar" => [{ start: 3, end: 6}],
"baz" => [{ start: 4, end: 5}],
"bap" => [{ start: 8, end: 9}]
]
# Would with some magic, become:
balance = float (raw_input ('What is your current balance? '))
interest = float (raw_input ('What is your interest rate? '))
monthly_interest_rate = interest / 12.0
# Monthly payment lower bound = Balance / 12.0
# Monthly payment upper bound = (Balance * (1 + (Annual interest rate / 12.0)) ** 12.0) / 12.0
lower_bound = balance / 12.0
upper_bound = ( balance * ( 1 + (monthly_interest_rate)) ** 12.0 ) / 12.0
working/ziplist ‹master✗›$ dig @192.168.1.1 ns zlcdn.com
; <<>> DiG 9.7.3-P3 <<>> @192.168.1.1 ns zlcdn.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44752
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 2
;; QUESTION SECTION:
@caryfitzhugh
caryfitzhugh / gist:2876863
Created June 5, 2012 18:44
Stored Procedures, Mongoid 3
class StoredProcedure
include Mongoid::Document
store_in collection: "system.js"
field :value, type: Moped::BSON::Code
field :name, type: String
field :_id, type: String, default: lambda { name }
def self.method_missing(name, *args)
arg_names = (1..args.length).map {|i| "a#{i}"}.join(',')
eval_str = "return function(#{arg_names}) { return #{name}(#{arg_names});}(#{args.map {|v| v.to_json}.join(',')});"
/Users/cfitzhugh/.rvm/gems/ruby-1.9.3-p385@ziplist/gems/sass-3.2.1/lib/sass/cache_stores/filesystem.rb:21: [BUG] Segmentation fault
ruby 1.9.3p385 (2013-02-06 revision 39114) [x86_64-darwin11.4.2]
-- Control frame information -----------------------------------------------
c:0117 p:0065 s:0503 b:0503 l:000502 d:000502 METHOD /Users/cfitzhugh/.rvm/gems/ruby-1.9.3-p385@ziplist/gems/sass-3.2.1/lib/sass/cache_stores/filesystem.rb:21
c:0116 p:0024 s:0495 b:0495 l:000494 d:000494 METHOD /Users/cfitzhugh/.rvm/gems/ruby-1.9.3-p385@ziplist/gems/sass-3.2.1/lib/sass/cache_stores/base.rb:62
c:0115 p:0017 s:0488 b:0488 l:000473 d:000487 BLOCK /Users/cfitzhugh/.rvm/gems/ruby-1.9.3-p385@ziplist/gems/sass-3.2.1/lib/sass/cache_stores/chain.rb:25
c:0114 p:---- s:0483 b:0483 l:000482 d:000482 FINISH
c:0113 p:---- s:0481 b:0481 l:000476 d:000480 IFUNC
c:0112 p:---- s:0479 b:0479 l:000478 d:000478 CFUNC :each
{
"rank" =>"NOT_CARE",
"match-expr" =>"NOT_CARE",
"hits" => {
"found" =>5,
"start" =>0,
"hit" => [
{
"id" =>373
},