Skip to content

Instantly share code, notes, and snippets.

@goliatone
goliatone / pretty_json.php
Created December 30, 2013 20:19
PHP Pretty json encode, for PHP < 5.4
<?php
function json_readable_encode($in, $indent = 0, Closure $_escape = null)
{
if (__CLASS__ && isset($this))
{
$_myself = array($this, __FUNCTION__);
}
elseif (__CLASS__)
{
@goliatone
goliatone / color.py
Created December 31, 2013 14:58
terminal color print
#!/usr/bin/env python
# Ported to Python from http://www.vim.org/scripts/script.php?script_id=1349
print "Color indexes should be drawn in bold text of the same color."
print
colored = [0] + [0x5f + 40 * n for n in range(0, 5)]
colored_palette = [
"%02x/%02x/%02x" % (r, g, b)
for r in colored
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8" />
<script src="jquery-1.7.2.min.js" ></script>
<script src="handlebars-1.0.0.beta.6.js" ></script>
<script src="underscore-min.js" ></script>
<script src="backbone-min.js" ></script>
@goliatone
goliatone / contract-generator.php
Created January 3, 2014 16:15
HTML Form: contract generator
<!doctype html>
<?php date_default_timezone_set('America/New_York');?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Stuff that won't be seen when printed */
.holder {display:block; background:#eee; border-bottom:#333 1px solid; box-shadow:0 0 4px #eee; padding:20px}
.holder h3 {margin-bottom:0}
form {width:980px; margin:0 auto}
@goliatone
goliatone / redraw.js
Created January 5, 2014 17:39
Force DOM redraw, webkit. Most of the time you want to prevent triggering a redraw, but some times browsers optimizations get in the way of a smooth animation.
//scale will trigger a redraw...
element.style.webkitTransform = 'scale(1)';
<!-- Drop this in ~/Library/Preferences/PyCharm20/tools -->
<!-- make sure you set the path to flake8 executable for your machine in the COMMAND option -->
<?xml version="1.0" encoding="UTF-8"?>
<toolSet name="Flake8">
<tool name="Flake8 File" showInMainMenu="true" showInEditor="true" showInProject="true" showInSearchPopup="false" disabled="false" useConsole="true" synchronizeAfterRun="true">
<exec>
<option name="COMMAND" value="/usr/local/bin/flake8" />
<option name="PARAMETERS" value="--max-line-length=120 --ignore=E301,E302,E261,E262,W404 $FileDir$/$FileName$" />
<option name="WORKING_DIRECTORY" value="$FileDir$" />

What is your folder-structure preference for a large-scale Node.js project?

0: Starting from Rails

This is the reference point. All the other options are based off this.

|-- app
|   |-- controllers
|   |   |-- admin
defmodule Test1 do
def upto(n) when n > 0 do
1..n |> Enum.map(&fizzbuzz/1)
end
defp fizzbuzz(n) when rem(n, 3) == 0 and rem(n, 5) == 0, do: "FizzBuzz"
defp fizzbuzz(n) when rem(n, 3) == 0, do: "Fizz"
defp fizzbuzz(n) when rem(n, 5) == 0, do: "Buzz"
defp fizzbuzz(n), do: n
@goliatone
goliatone / extend.js
Created February 16, 2014 04:13
Deep extend method
var extend = function extend(target) {
var sources = [].slice.call(arguments, 1);
sources.forEach(function (source) {
for (var property in source) {
if(source[property] && source[property].constructor &&
source[property].constructor === Object){
target[property] = target[property] || {};
target[property] = extend(target[property], source[property]);
} else target[property] = source[property];
}