Skip to content

Instantly share code, notes, and snippets.

View pizzapanther's full-sized avatar
🍕
Crushing it daily

Paul Bailey pizzapanther

🍕
Crushing it daily
View GitHub Profile
@pizzapanther
pizzapanther / Hello.jsx
Last active May 21, 2017 23:08
Hello World with Clock
import React, { Component } from 'react';
class HelloMessage extends Component {
constructor(props) {
super(props);
this.state = {date: new Date()};
}
componentDidMount() {
this.timerID = setInterval(
@pizzapanther
pizzapanther / shuffle.js
Last active May 1, 2017 01:55
Shuffle Array
/**
* Randomize array element order in-place.
* Using Durstenfeld shuffle algorithm.
*/
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
@pizzapanther
pizzapanther / fabfile.py
Last active April 19, 2017 16:18
Sample Fabric File
from fabric.api import run, env, sudo, cd, prefix
env.hosts = ['45.32.207.111']
env.user = 'paul'
DIR = '/home/paul/AppFish'
VENV = 'source /home/paul/.virtualenvs/appfish/bin/activate && source SECRETS.ENV'
def start ():
with cd(DIR):
@pizzapanther
pizzapanther / data_graph.js
Last active December 1, 2016 16:33
DataGraph: GraphQL query generator
var DataGraph = {};
DataGraph.query = function (opt) {
/***
options:
field: query field
filters: filters for query
attributes: attributes to return
nodes: return only node data, no page info
first: limit results
@pizzapanther
pizzapanther / benchmarks.md
Created November 30, 2016 21:06
DO vs Linode

DO

Apache

Test Results: 3316.19 3261.86 3349.77

Average: 3309.27 Requests Per Second

@pizzapanther
pizzapanther / gulpfile.js
Created November 3, 2016 15:42
Gulp file for compiling babel with rollup
var gulp = require('gulp');
var concat = require("gulp-concat");
var less = require('gulp-less');
var rollup = require('gulp-rollup');
var sourcemaps = require("gulp-sourcemaps");
var through = require('through2');
var uglify = require('gulp-uglify');
var util = require('gulp-util');
gulp.task('build-js', function () {
@pizzapanther
pizzapanther / response.py
Created October 5, 2016 19:53
Paginated Response for Django REST Framework
from django.conf import settings
from rest_framework.response import Response
class PaginatedResponse(Response):
def __init__(self, request, queryset, serializerClass, **kwargs):
pagination = settings.PAGINATION
page = request.GET.get('page', '1')
upstream app_server {
server 127.0.0.1:8000 fail_timeout=0;
}
# Default server configuration
server {
# SSL configuration
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
# To get Postgres to work without a password locally, change last part to "trust"
# /etc/postgresql/9.5/main/pg_hba.conf
# Database administrative login by Unix domain socket
local all postgres trust
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
@pizzapanther
pizzapanther / csv_json_denormalizer.py
Last active July 28, 2016 22:30
If you have a JSON column in a CSV, this recursively turns the JSON into columns
#!/usr/bin/env python3
import csv
import json
import begin
def denormalize (prefix, data, row):
if isinstance(data, dict):
for key, value in data.items():