Skip to content

Instantly share code, notes, and snippets.

(function() {
function async_load(){
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'http://yourdomain.com/script.js';
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
}
if (window.attachEvent)
@emilsoman
emilsoman / README.md
Created October 15, 2013 09:28
README for Rails apps
======

Development

Requirements

server is a Rails 4 application that is developed on Ruby 2.0. For the development environment it’s recommended to use the latest stable Ubuntu operating system ( 12.04 + ).

@emilsoman
emilsoman / custom_auth_failure_app.rb
Last active March 3, 2021 12:49
Custom failure app to render a custom json on auth failure
class CustomAuthFailure < Devise::FailureApp
def respond
self.status = 401
self.content_type = 'json'
self.response_body = {"errors" => ["Invalid login credentials"]}.to_json
end
end
@emilsoman
emilsoman / sessions_controller.rb
Created May 18, 2013 12:15
Customized SessionsController to render custom JSON on successful sign in
module Api
module V1
module CustomDevise
class SessionsController < Devise::SessionsController
prepend_before_filter :require_no_authentication, :only => [:create ]
include Devise::Controllers::Helpers
respond_to :json
def create
@emilsoman
emilsoman / bundle_outdated.rb
Last active December 16, 2015 01:09
'bundle outdated' extracted into a method
require 'bundler'
def outdated?(options = {})
gems = Array(options[:gems])
sources = Array(options[:source])
Bundler.definition.validate_ruby!
current_specs = Bundler.load.specs
if gems.empty? && sources.empty?
@emilsoman
emilsoman / development.md
Last active December 15, 2015 20:28
Ubuntu development environment

Guake terminal

  • login user shell
  • less transparency
  • height = fullscreen
  • add under Startup applications

Keyboard shortcuts

  • ctrl-F10 - Default browser

Google Chrome

(function(m,p){function s(a){var d=a.length,e=b.type(a);return b.isWindow(a)?!1:1===a.nodeType&&d?!0:"array"===e||"function"!==e&&(0===d||"number"==typeof d&&0<d&&d-1 in a)}function w(a,d,e,q){if(b.acceptData(a)){var n,r,A=b.expando,g="string"==typeof d,c=a.nodeType,k=c?b.cache:a,h=c?a[A]:a[A]&&A;if(h&&k[h]&&(q||k[h].data)||!g||e!==p)return h||(c?a[A]=h=ia.pop()||b.guid++:h=A),k[h]||(k[h]={},c||(k[h].toJSON=b.noop)),("object"==typeof d||"function"==typeof d)&&(q?k[h]=b.extend(k[h],d):k[h].data=b.extend(k[h].data,
d)),n=k[h],q||(n.data||(n.data={}),n=n.data),e!==p&&(n[b.camelCase(d)]=e),g?(r=n[d],null==r&&(r=n[b.camelCase(d)])):r=n,r}}function u(a,d,e){if(b.acceptData(a)){var q,n,r,A=a.nodeType,g=A?b.cache:a,c=A?a[b.expando]:b.expando;if(g[c]){if(d&&(r=e?g[c]:g[c].data)){b.isArray(d)?d=d.concat(b.map(d,b.camelCase)):d in r?d=[d]:(d=b.camelCase(d),d=d in r?[d]:d.split(" "));q=0;for(n=d.length;n>q;q++)delete r[d[q]];if(!(e?B:b.isEmptyObject)(r))return}(e||(delete g[c].data,B(g[c])))&&(A?b.cleanData([a],!0):b.sup
@emilsoman
emilsoman / chain-of-responsibility.js
Created February 21, 2013 11:31
Chain of Responsibility design pattern in Javascript
//Chain of responsibility design pattern
//Use strategyPipeline.handleRequest(request)
//to send the request to be handled along the
//chain-of-responsibility
var strategyPipeline = {
handleRequest: function(request){
var strategy1 = new Strategy1();
var strategy2 = new Strategy2();
@emilsoman
emilsoman / dining_philosopher.rb
Last active December 10, 2015 15:09
Ruby Program explaining the Dining Philosopher's problem
class Chopstick
attr_accessor :status
def initialize
@status = 'FREE'
end
end
class Member
attr_accessor :name, :chopsticks