Skip to content

Instantly share code, notes, and snippets.

View tastycode's full-sized avatar

Sasha Devol tastycode

  • Elsewhere Labs
  • New Orleans, LA
View GitHub Profile
@tastycode
tastycode / angular service
Created April 10, 2014 19:59
Deferred Event Queue Patterns
'use strict';
angular.module('rallyApp')
.service('EventQueue', function EventQueue($q) {
var eventQueues = {};
var listeners = {};
var triggerEvent = function(queue, event, listener) {
queue.splice(queue.indexOf(event), 1);
listener.cb(event);
@tastycode
tastycode / gist:90a8b38e11be463669ba
Created May 1, 2014 18:08
Convert $http promise to regular promise
Article.prototype.comments = function() {
var url = RouteIndex.comments($scope.article.id).relative();
var deferred = $q.defer();
$http.get(url).success(function(comments) {
deferred.resolve(comments);
});
return deferred.promise;
};
//usage
@tastycode
tastycode / globals.scss
Last active August 29, 2015 14:02
Common
@import "bourbon";
@import "neat";
@import "mixins";
html, body {
font-family: $font-proxima-nova;
font-size: $fs-root;
}
input, select, textarea {
@tastycode
tastycode / common_constants.rb
Created June 23, 2014 17:14
Common Constants
# Share constants between ruby and javascript
# Setup
# (in application.html.erb, or some place to inject javascript)
# MyApplication.constants = #{CommonConstants.to_json};
#
# Usage
# Ruby
# CommonConstants << "Math::PI"
# Javascript
# MyApplication.constants.MATH_PI
@tastycode
tastycode / gist:3da4984004f4b4a483c9
Last active August 29, 2015 14:09
Got a whole bunch of `fails` in your ruby codebase?
module FailClassInference
def fail(*args)
return super unless args.first.is_a?(String)
super(infer_exception_class, *args)
end
def raise(*args)
return super unless args.first.is_a?(String)
super(infer_exception_class, *args)
@tastycode
tastycode / null.rb
Created November 18, 2014 01:21
My null object
class Null
def !@
false
end
def nil?
true
end
def present?
@tastycode
tastycode / gist:daa84c0bbdb8b2c3a63a
Created December 10, 2014 23:37
Render rails templates from javascript handlebars templates
# config/initializers/sprockets.rb
module Sprockets::Helpers::RailsHelper
def view_renderer
@view_renderer ||= begin
view_paths = Rails::Application::Configuration.new(Rails.root).paths["app/views"]
ActionView::Base.new(view_paths).tap do |renderer|
def renderer.method_missing(name, *args)
router = Rails.application.routes.url_helpers
return router.send(name, *args) if router.respond_to?(name)
@tastycode
tastycode / gist:f66785f3915772b274ef
Created May 27, 2015 17:33
Find misplaced console.logs
> var ConsoleLogOld = console.log;
undefined
> console.log = function() {
... ConsoleLogOld.apply(null, Array.prototype.slice.apply(arguments))
... console.trace()
... }
[Function]
> console.log("meow")
/*
meow
@tastycode
tastycode / commands0
Created June 5, 2011 02:16
Gem Flaws
root@tara:~/tmp/1008583# locate images_controller.rb
/usr/lib/ruby/gems/1.8/gems/refinerycms-images-0.9.9.21/app/controllers/admin/images_controller.rb
root@tara:~/tmp/1008583# vim `locate images_controller.rb`
@tastycode
tastycode / phpmemcached.php
Created July 6, 2011 22:31
PHP Memcached Server
<?php
/**
* A really simple memcache implementation for PHP - Based on https://gist.github.com/949850
* Run the script, it listens on port 8000
* To store a value, http://localhost:8000/write/family/key/val
* To read a value , http://localhost:8000/read/family/key
*
* This is just a proof of concept .. it doesn't handle errors etc..
*