Skip to content

Instantly share code, notes, and snippets.

@danvine
danvine / string counter
Created April 7, 2011 05:40
stream analysis - string\tcount
| awk '{a[$0]++}END{for (i in a) print i"\t"a[i]}'
| perl -lne '++$a{$_} }{ print "$_\t$a{$_}" for keys %a'
⠝⠑⠗⠙
#
yum install net-snmp.x86_64
mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig
scp root@$IP:/etc/snmp/snmpd.conf /etc/snmp/snmpd.conf
chkconfig snmpd on
service snmpd start
@danvine
danvine / json_encode_pretty.php
Created September 9, 2011 18:07
Input an object, returns a json-ized string of said object, pretty-printed
<?php
/**
* Input an object, returns a json-ized string of said object, pretty-printed
*
* @author Unknown
* @param mixed $obj The array or object to encode
* @return string JSON formatted output
*/
function json_encode_pretty($obj, $indentation = 0) {
switch (gettype($obj)) {
@danvine
danvine / gist:1423241
Created December 2, 2011 13:29 — forked from bteitelb/gist:1423054
node-canvas shadowBlur test
// Step 1:
// Retrieve test image:
// wget http://s3.amazonaws.com/tastrix/440/large_orig/shiso_trans.png
//
// Step 2:
// Then, run this through node.js
//
// Step 3:
// Inspect shade_test.png; the overlayed squares have drop shadow with Gaussian blur, the circle of leaves does not
var Canvas = require('canvas')
@danvine
danvine / grrr.rb
Created February 2, 2012 04:05
2 models updated from 1 form view using rails 3.2.1
### Setup
mkdir 2_models_1_view
rails new 2_models_1_view
rails g scaffold Parent name:string age:integer
rails g scaffold Children toy:string hair:string eyes:string parent_id:integer
rake db:migrate
diff --git a/app/controllers/parents_controller.rb b/app/controllers/parents_controller.rb
index 4f6831f..ce6c226 100644
--- a/app/controllers/parents_controller.rb
+++ b/app/controllers/parents_controller.rb
@@ -25,6 +25,7 @@ class ParentsController < ApplicationController
# GET /parents/new.json
def new
@parent = Parent.new
+ @parent.children.build
diff --git a/app/controllers/parents_controller.rb b/app/controllers/parents_controller.rb
index 4f6831f..ce6c226 100644
--- a/app/controllers/parents_controller.rb
+++ b/app/controllers/parents_controller.rb
@@ -25,6 +25,7 @@ class ParentsController < ApplicationController
# GET /parents/new.json
def new
@parent = Parent.new
+ @parent.children.build
@danvine
danvine / rtail.sh
Created March 26, 2012 13:13
rails tail
#!/usr/bin/env bash
# filter out the noisy asset pipeline
tail -f ./log/development.log | egrep -v "(^$|GET|Served)"
@danvine
danvine / mercenary.sh
Created March 26, 2012 13:16
rails mercenary
#!/usr/bin/env bash
ps aux | fgrep 'ruby script/rails s -d' | awk '{print $2}' | xargs kill -9