Skip to content

Instantly share code, notes, and snippets.

View parshap's full-sized avatar

Parsha Pourkhomami parshap

View GitHub Profile
@parshap
parshap / sphero-gyro.js
Last active December 28, 2015 22:59
sphero "slow-motion hot potato" game hacked on at nodebots sf spherofest 11/20/2013 with @tc
var spheron = require('spheron');
var sphero = spheron.sphero();
var spheroPort = '/dev/cu.Sphero-BYR-RN-SPP';
sphero.on('open', function() {
console.log("opened");
var maskX = 0x1000,
maskY = 0x0800,
maskZ = 0x0400,
@parshap
parshap / gem_make.out
Created December 4, 2013 10:52
Ruby native extension error on SmartOS when `gem install ffi`
/usr/local/bin/ruby extconf.rb
checking for ffi.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
@parshap
parshap / user-recipe.rb
Created December 5, 2013 23:44
Chef cookbook get path to zsh and create user
NAME = "parshap"
# Create a resource to create the user (but do not execute)
create_user = user NAME do
gid NAME
supports :manage_home => true
home HOME
action :nothing
end
@parshap
parshap / Vagrantfile
Created December 8, 2013 23:49
Vagrant hooks
class Plugin < ::Vagrant.plugin("2")
name "build"
action_hook('build') do |hook|
hook.after(Vagrant::Action::Builtin::Provision, 2) do
system("bash build.sh")
end
end
end
@parshap
parshap / less-concat.js
Created December 9, 2013 20:12
Compile multiple less sources and concat results
module.exports = function(sources, options, callback) {
if ( ! callback) {
callback = options;
options = {};
}
options = _.defaults(options, LESS_OPTIONS);
async.map(sources, function(source, callback) {
compile(source, options, callback);
@parshap
parshap / pivot.js
Created December 18, 2013 09:19
Find pivot index
// Return the "pivot index" of the given array of numbers. The pivot index is
// the index where the sum of the numbers on the left is equal to the sum of
// the numbers on the right.
function pivot(numbers) {
validateInput(numbers);
// Find a pivot index by testing each index
for (var i = 0; i < numbers.length; i++) {
var leftSum = sum(numbers.slice(0, i));
var rightSum = sum(numbers.slice(i + 1));
select sum(transactions.price) from sellers
left join products on products.seller_id = sellers.id
left join purchases on purchases.product_id = products.id
left join transactions on transactions.purchase_id = purchases.id
where sellers.id = SELLER_ID and
transactions.is_payed = 0 and
transactions.date <= date_sub(now(), interval 1 week)
@parshap
parshap / cluster-reload.js
Created December 22, 2013 16:34
Node.js zero-downtime reload with cluster
var cluster = require("cluster");
function master() {
var worker = cluster.fork();
process.on("SIGUSR2", function() {
var newWorker = cluster.fork();
newWorker.on("listening", function() {
worker.disconnect();
worker = newWorker;
@parshap
parshap / README.md
Last active January 1, 2016 16:49
Ruby CSV Parsing

CSVParser

Parse CSV rows by defining parsing blocks for individual columns.

Each row is parsed one-by-one. First a new Hash is initialized to store data for the row. Then, each individual column is parsed by calling matching parsing blocks. Parsing blocks are passed the column's value and header key and can set arbitrary state on the Hash for the current row.

Usage

Example: