Skip to content

Instantly share code, notes, and snippets.

@abriening
abriening / default.conf
Created February 19, 2018 18:36
Default nginx route, close connection.
server {
listen 80 default_server;
server_name _;
return 444;
}
function observer(){
var observers = [];
return {notify: notify, subscribe:subscribe}
function subscribe(callback){
observers.push(callback);
var i = observers.length - 1;
return function(){
observers[i] = function(){}
}
@abriening
abriening / coverage.diff
Last active January 4, 2016 21:29
simplecov for rails
diff --git a/.gitignore b/.gitignore
index e2aa052..9a467fb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,12 +5,12 @@
# git config --global core.excludesfile ~/.gitignore_global
# Ignore bundler config
-/.bundle
+.bundle/
@abriening
abriening / fixtures.js
Created October 4, 2013 13:09
Loads html fixtures for javascript "unit" testing. Works with FireFox and fixtures in the same folder (will get same-origin-policy errors otherwise). Works with mocha/qunit/jasmine via phantom. I should remove dependency on jQuery ($ parameter).
function Fixtures($) {
var id, container;
function setup(files) {
for(var i = 0; i < files.length; i++) {
load(files[i])
}
}
function createContainer() {
@abriening
abriening / goals_controller.rb
Created August 24, 2013 21:28
How pretty the Rails 3 controllers can be.
class GoalsController < ApplicationController
respond_to :html, :json
before_action :set_goal, only: [:show, :edit, :update]
def show
respond_with @goal
end
def edit
respond_with @goal
@abriening
abriening / aliases.sh
Created May 24, 2013 19:26
ls aliases
alias ls='ls -F'
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'
alias lsa='ls -al'
@abriening
abriening / Preferences.sublime-settings.json
Last active December 17, 2015 17:19
Sublime Text user preferences
{
"color_scheme": "Packages/Color Scheme - Default/SpaceCadet.tmTheme",
"default_line_ending": "unix",
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"font_size": 15.0,
"highlight_column": true,
"highlight_line": true,
"highlight_modified_tabs": true,
"show_tab_close_buttons": false,
class PostPolicy < Struct.new(:user, :post)
def update?
post.user == user
end
def destroy?
false
end
def show?
true
end
class Proc
def bind(receiver)
unbound_method = receiver.class.unbound_method self
unbound_method.bind receiver
end
end
class Object
def self.unbound_method(proc)
define_method :__temp_unbound_method__, &proc
Node = Struct.new(:value, :left, :right)
node = Node.new(24, Node.new(12, Node.new(10), Node.new(14)), Node.new(28, nil, Node.new(30)))
def values(node)
return [] if node.nil?
[values(node.left),
node.value,
values(node.right)].flatten
end