Skip to content

Instantly share code, notes, and snippets.

View vesan's full-sized avatar

Vesa Vänskä vesan

View GitHub Profile
@decasia
decasia / ember-transaction-helpers.coffee
Created January 29, 2014 19:34
Helper code that makes an Ember model aware of whether its children are dirty
App.Key.reopen
################################################
##### Transaction setup handlers
################################################
transactionArray: []
setupTransaction: ->
@set 'transactionArray', []
Ember.Test.registerAsyncHelper('submitForm',
function(app, selector, context) {
var $el = findWithAssert(selector, context);
Ember.run(function() {
$el.submit();
});
}
);
// Example Usage
// fs_stat :: String -> (Error -> Stat -> ()) -> ()
var fs_stat = _.curry(fs.stat, 2);
// paths :: [String]
var paths = ['file1.txt', 'file2.txt', 'file3.txt'];
// tmp :: [(Error -> Stat -> ()) -> ()]
var tmp = paths.map(oneparam(fs_stat));
// async.parallel :: [(Error -> a -> ()) -> ()] -> (Error -> [a] -> ()) -> ()
Ember.Application.initializer({
name: 'currentUser',
initialize: function(container, application) {
var user,
store = container.lookup('store:main'),
attributes = $('meta[name="current-user"]').attr('content');
if (attributes) {
var serializer = store.serializerFor(App.User);

An ActiveRecord conundrum

I'm going to describe a weird problem I faced when using ActiveRecord today. To protect the innocent, I'm not going to talk about the app I'm actually working on but will instead discuss a hypothetical but isomorphic database design for a clone of the popular blogging platform Tumblr.

Tumblr lets you publish various different sorts of content. We might be tempted to shove all these types in a big STI table, but the types are all quite different from one another and so we give them their own tables.

@PetrKaleta
PetrKaleta / Rakefile
Last active August 29, 2015 14:01
Heroku deploy rake tasks with hooks. Demonstrates how to trigger Sidekiq to quiet or terminate via API before deploy
# List of environments and their heroku git remotes (id: 'remote_name')
HEROKU_ENVIRONMENTS = {
staging: 'staging-remote-name',
production: 'production-remote-name'
}
namespace :deploy do
# Create rake tasks to deploy on Heroku environments
# $ rake -T deploy
# rake deploy:production # Deploy to production
@tomdale
tomdale / logger.js
Last active August 29, 2015 14:02
Excerpt of the formatted, hierarchical logger in Skylight
/*
Example usage:
import logger from "app/system/logger";
var LOG = logger.loggerFor("topic"');
LOG.log({
event: "data received",
secondary: {
resource: "photo",
@ptrhvns
ptrhvns / gist:2b0ebe54071ae71982f4
Created July 31, 2014 20:38
Must-Read Software Developer Books
Clean Code - Martin
Code Complete - McConnell
Compilers - Aho
Computer Networks (5th Edition) - Tanenbaum
Design Patterns - Gamma, et al
Domain-Driven Design - Evans
Growing Object-Oriented Software, Guided by Tests - Freeman, et al
Introduction to Automata Theory, Languages, and Computation - Hopcroft
Purely Functional Data Structures - Okasaki
Refactoring - Fowler
@pond
pond / gist:5eaec0c30c0b4477f234
Last active August 29, 2015 14:05
PostgreSQL "active?" Rails adapter check async patch
# This monkey patches the PostgreSQL adapter to use asynchronous
# communication when doing its "SELECT 1" check for is-connection-active.
# One symptom of this problem is stalled processing queues in Sidekiq.
# See also:
#
# https://github.com/rails/rails/issues/12867
#
# At the time of writing we have seen indefinite blocking down in the C
# library's "poll()" method due to the out-of-box Rails code using blocking
# I/O, in multithreaded environments - one thread gets stuck in the I/O and
# Run the given block +num+ times and then print out the mean, median, min,
# max, and stddev of the run. For example:
#
# irb> stats(10) { sleep(rand / 100) }
# mean: 5.99ms
# median: 6.76ms
# min: 1.49ms
# max: 9.28ms
# stddev: 2.54ms
def stats(num)