Skip to content

Instantly share code, notes, and snippets.

View eristoddle's full-sized avatar

Stephan Miller eristoddle

View GitHub Profile
@eristoddle
eristoddle / merge_csv.py
Created April 25, 2016 17:49
Merge csvs with Pandas
from glob import iglob
import pandas as pd
files = sorted(iglob('*.csv'))
frames = [ pd.read_csv(f) for f in files ]
result = pd.concat(frames)
final_csv = result.to_csv('./final.csv')
@eristoddle
eristoddle / new_gist_file.ps1
Created March 29, 2016 16:45
Powershell script to parse xml in csv and expand it
$records = Import-Csv BadResults.csv
foreach($record in $records){
$xml = new-object System.Xml.XmlDocument
$fraudScore = $record.FraudScoreDetails
$xml.LoadXml($fraudScore)
foreach ($i in $xml.response.rule){
#Write-Output $i.criteriaEvaluated
#Write-Output $i.evaluationResult
$record | Add-Member NoteProperty $i.criteriaEvaluated $i.evaluationResult
@eristoddle
eristoddle / appify
Created November 2, 2015 18:25 — forked from mathiasbynens/appify
appify — create the simplest possible Mac app from a shell script
#!/bin/bash
if [ "$1" = "-h" -o "$1" = "--help" -o -z "$1" ]; then cat <<EOF
appify v3.0.1 for Mac OS X - http://mths.be/appify
Creates the simplest possible Mac app from a shell script.
Appify takes a shell script as its first argument:
`basename "$0"` my-script.sh
#include <unistd.h>
#include <node.h>
#include <string.h>
#include <v8.h>
using namespace v8;
unsigned long long count = 0;
// native blocking/compute intensive function
@eristoddle
eristoddle / revert.sh
Last active August 29, 2015 14:21 — forked from kugaevsky/revert.sh
$ cd /usr/local
$ git checkout b64d9b9c431642a7dd8d85c8de5a530f2c79d924 Library/Formula/node.rb
$ brew unlink node
$ brew install node
$ npm install -g npm@latest
#!/bin/bash
# nodereinstall
# credit: http://stackoverflow.com/a/11178106/2083544
#
# UPDATE: I've converted this gist to a repo:
# https://github.com/brock/node-reinstall
#
# get sudo
@eristoddle
eristoddle / pre-render.js
Last active August 29, 2015 14:20 — forked from mef/pre-render.js
// pre-render d3 charts at server side
var d3 = require('d3')
, jsdom = require('jsdom')
, fs = require('fs')
, htmlStub = '<html><head></head><body><div id="dataviz-container"></div><script src="js/d3.v3.min.js"></script></body></html>'
jsdom.env({
features : { QuerySelector : true }
, html : htmlStub
, done : function(errors, window) {
// Pre-render d3 force-directed graph at server side
// Call node pre_render_d3_graph.js to generate d3_graph.html
// Original idea and framework borrowed from https://gist.github.com/mef/7044786
var d3 = require('d3')
, jsdom = require('jsdom')
, fs = require('fs')
, htmlStub = '<html><head> \
<style>.node { stroke: #fff; fill: #ccc; stroke-width: 1.5px; } \
.link { stroke: #333; stroke-opacity: .5; stroke-width: 1.5px; }</style> \
@eristoddle
eristoddle / Application.php
Created March 13, 2015 16:45
Phalcon PHP Framework environment switching
<?php
//...
protected function _setEnvironment($config)
{
$env = new \stdClass();
if (array_key_exists('ENV', $_SERVER) && isset($_SERVER['ENV'])) {
$env->name = $_SERVER['ENV'];
} else {
$env->host = $_SERVER['HTTP_HOST'];
foreach ($config['domains'] as $k => $v) {
@eristoddle
eristoddle / Application.php
Created March 13, 2015 16:39
Multiple database connections in Phalcon PHP Framework
<?php
//...
foreach ($config->databases as $db => $cred) {
$this->di->set($db, function () use ($cred) {
$adaptor = "\\Phalcon\\Db\\Adapter\\Pdo\\{$cred->adapter}";
return new $adaptor([
'host' => $cred->host,
'username' => $cred->username,
'password' => $cred->password,
'dbname' => $cred->dbname