Skip to content

Instantly share code, notes, and snippets.

View gingerlime's full-sized avatar

gingerlime

View GitHub Profile
source "https://rubygems.org"
gem "rubocop", :require => false
import boto3
import json
lambda_client = boto3.client('lambda')
def invoke(event, context):
lambda_client.invoke(
FunctionName='arn:aws:lambda:us-east-1:...:function:...',
InvocationType='Event',
@gingerlime
gingerlime / sidekiq.log
Created January 11, 2015 16:55
sidekiq redis connection errors
2015-01-11T16:02:16.656Z 11444 TID-42mh0 ERROR: /var/local/deployment/vendor/bundle/ruby/2.2.0/gems/redis-3.1.0/lib/redis/connection/ruby.rb:55:in `rescue in _read_from_socket'
2015-01-11T16:02:16.656Z 11444 TID-42mh0 ERROR: /var/local/deployment/vendor/bundle/ruby/2.2.0/gems/redis-3.1.0/lib/redis/connection/ruby.rb:48:in `_read_from_socket'
2015-01-11T16:02:16.656Z 11444 TID-42mh0 ERROR: /var/local/deployment/vendor/bundle/ruby/2.2.0/gems/redis-3.1.0/lib/redis/connection/ruby.rb:41:in `gets'
2015-01-11T16:02:16.656Z 11444 TID-42mh0 ERROR: /var/local/deployment/vendor/bundle/ruby/2.2.0/gems/redis-3.1.0/lib/redis/connection/ruby.rb:273:in `read'
2015-01-11T16:02:16.656Z 11444 TID-42mh0 ERROR: /var/local/deployment/vendor/bundle/ruby/2.2.0/gems/redis-3.1.0/lib/redis/client.rb:238:in `block in read'
2015-01-11T16:02:16.656Z 11444 TID-42mh0 ERROR: /var/local/deployment/vendor/bundle/ruby/2.2.0/gems/redis-3.1.0/lib/redis/client.rb:226:in `io'
2015-01-11T16:02:16.656Z 11444 TID-42mh0 ERROR: /var/local/deployment/ve
config.middleware.insert_before ActionDispatch::ParamsParser, ::Rack::Robustness do |g|
g.no_catch_all
# you might need to replace this with JSON::ParserError, depending on your Rails configuration
# or you can catch both...
g.on(MultiJson::ParseError) { |ex| 400 }
g.content_type 'text/plain'
g.body{ |ex| ex.message }
g.ensure(true) do |ex|
env['rack.errors'].write(ex.message)
logger.warn(ex.message)
@gingerlime
gingerlime / test.py
Created February 15, 2014 19:00
trying to use url_prefix with Flask
#!/usr/bin/env python
# coding=utf8
from flask import Flask, Blueprint, redirect, url_for
from flask.ext.bootstrap import Bootstrap
bp = Blueprint('blueprint', __name__)
app = Flask(__name__)
Bootstrap(app)
app.register_blueprint(bp, prefix='/prefix')
@gingerlime
gingerlime / analytics_js_loader.js.erb
Created November 20, 2013 21:41
analytics.js loader for rails
// sources: https://segment.io/libraries/analytics.js#getting-started
// https://github.com/phillbaker/analytics-js-rails/blob/master/app/views/analytics-js/_loader.html.erb
// Create a queue, but don't obliterate an existing one!
window.analytics || (window.analytics = []);
// A list of all the methods in analytics.js that we want to stub.
window.analytics.methods = ['identify', 'track', 'trackLink', 'trackForm',
'trackClick', 'trackSubmit', 'page', 'pageview', 'ab', 'alias', 'ready',
'group', 'on', 'once', 'off'];
@gingerlime
gingerlime / devise_mail_helpers.rb
Last active December 23, 2015 13:09 — forked from stevenharman/devise_mail_helpers.rb
small tweaks using `text_part` and slightly changed regex
module Features
module MailHelpers
def last_email
ActionMailer::Base.deliveries.last
end
# Can be used like:
# extract_token_from_email(:reset_password)
def extract_token_from_email(token_name)
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
@gingerlime
gingerlime / redis-request-irregularities-ruby.md
Created November 1, 2012 11:40
Redis Request iRregularities with Ruby

... I couldn't resist the temptation for some pseudo-alliteration.

Need for speed

When it comes to driving, I'm a rather slow driver. I can parallel park with my eyes-closed, merge in traffic easily, but I really don't enjoy driving fast (Mind you, I take public transport these days). But when it comes to squeezing performance out of a system, I guess I'm much more attracted to the idea of things running fast. The redis attraction is therefore quite obvious. In-memory database. It doesn't get much faster than that.

Bumps on the road

It was rather surprising to come across speed issues with redis, and fairly early-on with our project. At kenHub, we are building an anatomy learning platform. The platform must adapt to each and every student, and present them with the best question for their level. To do this, we must store statistics for each and every anatomy term for each user. Redis was a natural candidate for this. Quick access to read/write individual records allows us to u

class BlaController < ApplicationController
skip_before_filter :authenticate_user!
def index