Skip to content

Instantly share code, notes, and snippets.

gingerlime

Block or report user

Report or block gingerlime

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Gemfile
source "https://rubygems.org"
gem "rubocop", :require => false
View invoke.py
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 Jan 11, 2015
sidekiq redis connection errors
View sidekiq.log
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
View application.rb
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 Feb 15, 2014
trying to use url_prefix with Flask
View test.py
#!/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 Nov 20, 2013
analytics.js loader for rails
View analytics_js_loader.js.erb
// 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 Dec 23, 2015 — forked from stevenharman/devise_mail_helpers.rb
small tweaks using `text_part` and slightly changed regex
View devise_mail_helpers.rb
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)
View .gitignore
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
@gingerlime
gingerlime / redis-request-irregularities-ruby.md
Created Nov 1, 2012
Redis Request iRregularities with Ruby
View redis-request-irregularities-ruby.md

... 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

View bla_controller.rb
class BlaController < ApplicationController
skip_before_filter :authenticate_user!
def index
You can’t perform that action at this time.