Skip to content

Instantly share code, notes, and snippets.

@rockwood
rockwood / server.js
Created July 19, 2012 16:22
Node Static File Server
var http = require('http');
var fs = require('fs');
var path = require('path');
var PORT = 3000;
var INDEX = './index.html';
http.createServer(function (request, response) {
console.log('request starting...');
@rockwood
rockwood / bem.md
Created April 14, 2016 19:43
BEM Conventions

Dos:

Avoid page specific stylesheets

It's easy to organize styles by page when the app is small, but a year from now we'll probably have 50+ pages and having a separate stylesheet for each page will result in tons of duplication.

Use the grid as much as possible

The grid has a ton of feature and it's really customizable from variables.scss. Anywhere you're doing multi-column layouts, try to use the grid.

@rockwood
rockwood / archive_post_scenario.ex
Last active November 27, 2018 07:24
Ecto Soft-Delete Pattern
defmodule MyApp.ArchivePostScenario do
alias MyApp.Repo
alias Ecto.Multi
alias __MODULE__.Query
def run(options) do
post = Keyword.fetch!(options, :post)
archive_and_delete([
comments: Query.comments(post),
@rockwood
rockwood / split_csv.bash
Last active June 29, 2018 00:08
Split CSV Files
#!/usr/bin/env bash
input_file=$1
header_file=./output/headers.csv
rows_file=./output/rows.csv
mkdir -p ./output
head -1 $input_file > $header_file
tail -n +2 $input_file > $rows_file
@rockwood
rockwood / Readme.md
Last active May 4, 2018 15:55
Seoul Elixir Meetup

1. Install Phoenix 1.3

mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez

2. Create a new Phoenix project

mix phx.new demo

3. Create the database

@rockwood
rockwood / rps.ex
Created January 17, 2018 12:28
Rock Paper Scissors
defmodule Rps do
def run(input) do
player1 = String.split(input, "")
player2 = Enum.shuffle(["r", "p", "s"])
result =
[player1, player2]
|> Enum.zip()
|> Enum.map(&result/1)
|> Enum.sum()
|> case do

Ranger Keybindings

Search for a File / Directory

Key Binding Description
f search for file / directory

Copy, Rename/Move or Delete

@rockwood
rockwood / app.js
Created February 10, 2012 20:29
Flatiron view loader
var flatiron = require('flatiron'),
path = require('path'),
plates = require('plates'),
app = flatiron.app;
app.config.file({ file: path.join(__dirname, 'config', 'config.json') });
app.use(flatiron.plugins.http);
app.use(require("./plugins/load"));
@rockwood
rockwood / gist:1562615
Created January 4, 2012 22:43
Everyauth findUserById
var UserSchema = new Schema({
email : String,
hashed_password : String,
first_name : String,
last_name : String,
salt : String,
auth_method : String,
signupDate : { type: Date, default: Date.now }
});
class TestServer
def initialize(options)
@server_port = options.fetch(:server_port)
@client_port = options.fetch(:client_port)
end
def start
@pid = spawn(command)
end