Skip to content

Instantly share code, notes, and snippets.

View juliocesar's full-sized avatar

Julio Cesar Ody juliocesar

View GitHub Profile
describe "Asynchronous specs", ->
funcRunInBackground = ->
value = 1
wrapFuncRunInBackground = (done) ->
# setup for simmulating the async operation, a function run in the background
setTimeout ->
funcRunInBackground()
done()
, 3000
@juliocesar
juliocesar / breakpoint.sass
Created February 10, 2014 21:47
A breakpoints mixin I use, taken from some post by Chris Coyer that I can't remember right now.
// Screen size breakpoints
// =======================
//
// Example usage:
//
// .page-header
// +breakpoint(desktop)
// width: 50%
// +breakpoint(tablet)
// width: 80%
// Prefix mixins
// =============
//
// A set of SASS mixins for abstracting vendor prefixes.
@mixin background-size($parameters)
-webkit-background-size : $parameters
-moz-background-size : $parameters
-o-background-size : $parameters
background-size : $parameters
# Capistrano deployment file
# ==========================
#
# Deployment requires that you can log in as "web", which means you'll
# need it's password.
require 'bundler/capistrano'
set :rvm_ruby_string, :local # Use the same ruby as used locally for deployment
set :rvm_autolibs_flag, "read-only" # More info: rvm help autolibs
@juliocesar
juliocesar / gist:6409580
Last active December 22, 2015 03:19
Kool console
# Kool console
# ============
#
# A snippet for running CoffeeScript snippets in browser, with a cool
# centered text input.
#
# Press <meta> + K to open the console.
# Styles for the text field.
CSS = """
# Multiple models/collections event tracking
# ==========================================
#
# This is handy, for instance, when something needs to happen once a set
# of collections fire `sync`. For example:
#
# Backbone.Events.when [User, Projects], 'sync', ->
# alert 'carry on with all the data ready'
Backbone.Events.when = (models, track, callback) ->
@juliocesar
juliocesar / gist:5997750
Last active December 19, 2015 18:19
Enabling caching in Sprockets
# Enables caching in Sprockets
# ============================
#
# I couldn't find it documented anywhere until I searched for it. Sprockets will recompile
# every file in a manifest for every request it serves if even *one* file in it changes,
# which it really slow for developing anything.
#
# This fixes that by ensuring only files that get changed get recompiled. NOTE: This is
# just an example. What you're looking for is in line 14.
@juliocesar
juliocesar / gist:5993429
Created July 14, 2013 06:44
Controller-less router
# Application router
# ==================
#
# Written for https://medium.com/what-i-learned-building/89e504dd8313.
# This is how it'd look like without the pattern applied.
class Router extends Backbone.Router
routes:
'users/:id/posts' : ->
@juliocesar
juliocesar / gist:5790235
Last active December 18, 2015 13:29
ActiveRecord question

AR association with special attributes

Is there a straightforward way to have an intermediate model in AR (has many through type of scenario) which adds attributes to the association?

E.g.: has_many :fruits, :through => :qualified_fruits, :class_name => 'Fruit'.

Fruit objects returned have a "quality" attribute which actually lives in :qualified_fruits.

@juliocesar
juliocesar / modules.js
Created May 3, 2013 04:51
ES6 - modules
// ES6 modules
// =============
// Compartments of code in ES6. Declared as strings with a keyword.
module 'fruit' {
export var list = ['Apple', 'Banana', 'Grape'];
export var makeSmoothie = function() {
// ...