Skip to content

Instantly share code, notes, and snippets.

@dre1080
dre1080 / gist:988488
Created May 24, 2011 10:27
Simple ini parser
$debug = function($var, $exit = true) {
echo '<pre>';
(is_array($var) || is_object($var)) ? print_r($var) : var_dump($var);
echo '</pre>';
if ($exit)
exit;
};
$parse = function($file, $show_debug = false) use ($debug) {
@dre1080
dre1080 / async_iteration.js
Created February 20, 2012 12:03
Everything in node happens at the same time, which means, unless you're doing your processing inside your callbacks, you cannot guarantee asynchronous functions have completed yet.
/**
* Source: http://stackoverflow.com/questions/6287908/nodejs-express-fs-iterating-files-into-array-or-object-failing
*/
var fs = require('fs'),
EventEmitter = require('events').EventEmitter,
filesEmitter = new EventEmitter(),
files = [];
// this event will be called when all files have been added to the files array
@dre1080
dre1080 / watch.sh
Created April 27, 2012 04:57
Compile and watch Sass (using Compass) and CoffeeScript files with one command
#!/bin/bash
type -P compass &>/dev/null || { echo "Compass command not found."; exit 1; }
type -P coffee &>/dev/null || { echo "Coffee command not found."; exit 1; }
# Get current directory (project path)
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SASS_DIR="$DIR/public/stylesheets/sass/"
CSS_DIR="$DIR/public/stylesheets/"
@dre1080
dre1080 / burp.md
Last active October 6, 2015 22:38
How to code drunk

How to code drunk

Some people born with it, some people are self-taught on this, some people just discover how. How about a guide on how to code great software while still drunk as a cow?

Rules

  • You can add your patterns by forking this gist.
  • You must be drunk before sending a pattern.
@dre1080
dre1080 / varbinary_migration_columns_initializer.rb
Created August 24, 2012 14:18
Setup varbinary columns or any other unsupported data type in rails migrations
# Provide varbinary columns in a Migration.
# Probably a better way to do this?
#
# Usage:
# => t.varbinary :column, :limit => 20, ....[options]
#
ActiveRecord::ConnectionAdapters::SchemaStatements.module_eval do
def type_to_sql_with_varbinary(type, limit = nil, precision = nil, scale = nil)
return type_to_sql_without_varbinary(type, limit, precision, scale) unless :varbinary == type.to_sym
@dre1080
dre1080 / .powenv
Last active March 21, 2018 14:06
Using Pow!! with Foreman (Configuration)
# In your app's root.
# Make Pow!! export all the env variables contained in the .env file used by Foreman.
export $(cat .env)
@dre1080
dre1080 / all2coffee.sh
Created November 9, 2013 01:25
Js2Coffee a directory recursively. Excludes node_modules, app/assets and public directories.
for FILE in `find . -name "*.js" -type f -o -path './node_modules' -prune -o -path './app/assets' -prune -o -path './public' -prune`
do
if [ -e $FILE ] ; then
COFFEE=${FILE//.js/.coffee}
echo "converting ${FILE} to ${COFFEE}"
js2coffee "$FILE" > "$COFFEE"
else
echo "File: {$1} does not exist!"
fi
@dre1080
dre1080 / util.go
Last active September 30, 2015 21:29
Print Echo registered routes
package util
import (
"log"
"strings"
"github.com/labstack/echo"
)
// DebugPrintRoutes prints all registered routes of e.
@dre1080
dre1080 / soft-delete.sql
Last active February 10, 2016 10:08
Soft-deletable records in Postgres
CREATE FUNCTION soft_delete()
RETURNS trigger AS $$
BEGIN
EXECUTE 'UPDATE '
|| TG_TABLE_NAME
|| ' SET deleted_at = current_timestamp WHERE id = $1'
USING OLD.id;
RETURN OLD;
END;
$$ LANGUAGE plpgsql
@dre1080
dre1080 / localhost-tld.md
Last active April 18, 2020 10:52 — forked from marek-saji/dev-tld.md
Configure local DNS server to serve *.localhost domains

Configure local wildcard DNS server

  1. Install Dnsmasq: sudo apt-get install dnsmasq

  2. Since Ubuntu's NetworkManager uses dnsmasq, and since that messes things up a little for us, open up /etc/NetworkManager/NetworkManager.conf and comment out (#) the line that reads dns=dnsmasq. Restart NetworkManager afterwards: sudo systemctl restart NetworkManager.

  3. Make sure Dnsmasq listens to local DNS queries by editing /etc/dnsmasq.conf, and adding the line listen-address=127.0.0.1.