Skip to content

Instantly share code, notes, and snippets.

@ryana
ryana / my_model.rb
Created June 29, 2011 01:45
A simple fragment caching example in Rails 3
class Conversation
#...
after_create :expire_dash_cache
def add_new_comments(comments)
# Do stuff w/ the new comments...
save
expire_dash_cache
@ryana
ryana / dada_memcache_reloads.rb
Created July 7, 2011 00:16
Thoughts on reloading github.com/trada/dada.git configs w/ a memcache triggers
# Note: not tested at all
module Dada
attr_accessor :config_reload_timestamp
def dalli
@dalli ||= Dalli::Client.new(client_args)
end
def check_config_timestamp
@ryana
ryana / Gemfile.rb
Created July 8, 2011 17:13
FourthSegment Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.7'
gem 'jquery-rails', '0.2.7'
gem 'uuid'
gem 'bson_ext'
gem 'mongo_ext'
gem 'mongo_mapper', '0.9.1'
gem 'devise'
gem 'mm-devise'
@ryana
ryana / tha_jesus.txt
Created September 12, 2011 21:00
do not fuck with
ra:~ ryan$ nl scope.c
1 int main() {
2 int c = 0;
3 if (1) {
4 int i = 0;
5 }
6 c = 5;
7 i = 10;
@ryana
ryana / mini_pca.rb
Created September 27, 2011 05:17
ruby-svd seg fault
require 'ruby-svd'
class MiniPca
def self.go
var_count = 300
doc_count = 100
m = SVDMatrix.new(doc_count, var_count)
doc_count.times do |n|
@ryana
ryana / hydra.rb
Created October 7, 2011 16:36
hydra is hawt
ruby-1.9.2-p180 :033 > Benchmark.measure { urls.each {|u| req = Typhoeus::Request.new(u); req.on_complete {|resp| puts [resp.code, resp.body.size].map(&:to_s).join(', ') }; hydra.queue(req) }; hydra.run }
301, 242
302, 352
301, 337
302, 0
301, 0
200, 3291
301, 350
301, 178
301, 417
@ryana
ryana / errors.js
Last active September 30, 2015 16:30
Popup Ramen error question on AJAX error
// Ask Ramen 500 question on AJAX error
$(document).ajaxComplete(function(e, xhr, opts) {
// You may want to also catch 401, 403, 406, 422, etc....
// Talk with your developers to figure out which status codes
// need to be monitored.
if (xhr.status > 499 && xhr.status < 510) {
if (Ramen) {
Ramen.event("560ad1f87765626520281000");
}
}
@ryana
ryana / gist:2891714
Created June 7, 2012 21:41
UnixBench on our SoftLayer box
sg@max:/tmp/UnixBench$ ./Run
gcc -o ./pgms/arithoh -DTIME -Wall -pedantic -ansi -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall -Darithoh ./src/arith.c
gcc -o ./pgms/register -DTIME -Wall -pedantic -ansi -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall -Ddatum='register int' ./src/arith.c
gcc -o ./pgms/short -DTIME -Wall -pedantic -ansi -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall -Ddatum=short ./src/arith.c
gcc -o ./pgms/int -DTIME -Wall -pedantic -ansi -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall -Ddatum=int ./src/arith.c
gcc -o ./pgms/long -DTIME -Wall -pedantic -ansi -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall -Ddatum=long ./src/arith.c
gcc -o ./pgms/float -DTIME -Wall -pedantic -ansi -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall -Ddatum=float ./src/arith.c
gcc -o ./pgms/double -DTIME -Wall -pedantic -ansi -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall -Ddatum=double ./src/arith.c
gcc -o ./pgms/hanoi -DTIME -Wall -pedantic -ansi -O2 -fomi
@ryana
ryana / gist:2891715
Created June 7, 2012 21:42
UnixBench on our SoftLayer box
sg@max:/tmp/UnixBench$ ./Run
gcc -o ./pgms/arithoh -DTIME -Wall -pedantic -ansi -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall -Darithoh ./src/arith.c
gcc -o ./pgms/register -DTIME -Wall -pedantic -ansi -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall -Ddatum='register int' ./src/arith.c
gcc -o ./pgms/short -DTIME -Wall -pedantic -ansi -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall -Ddatum=short ./src/arith.c
gcc -o ./pgms/int -DTIME -Wall -pedantic -ansi -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall -Ddatum=int ./src/arith.c
gcc -o ./pgms/long -DTIME -Wall -pedantic -ansi -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall -Ddatum=long ./src/arith.c
gcc -o ./pgms/float -DTIME -Wall -pedantic -ansi -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall -Ddatum=float ./src/arith.c
gcc -o ./pgms/double -DTIME -Wall -pedantic -ansi -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall -Ddatum=double ./src/arith.c
gcc -o ./pgms/hanoi -DTIME -Wall -pedantic -ansi -O2 -fomi
@ryana
ryana / push_to_knowtify.rb
Created December 2, 2015 23:53
ChartURL / Knowtify.io Integration Example Part 2
# Part 1 at https://gist.github.com/ryana/7e64954d8dd15c858f30
def push_data_to_knowtify
api_token = "SEKRIT"
headers = {'Authorization' => "Token token=#{api_token}", 'Content-Type' => "application/json"}
url_base = "http://www.knowtify.io/api/v1"
endpoint = "/contacts/upsert"
data = {
contacts: [
{