Skip to content

Instantly share code, notes, and snippets.

Avatar

Jason Kraus zbyte64

  • Kraus Dev House
  • Fresno, CA USA
View GitHub Profile
View debug_middleware.py
from django.views.debug import technical_500_response
import sys
import webbrowser
import tempfile
class BrowserExceptionMiddleware(object):
def process_exception(self, request, exception):
response = technical_500_response(request, *sys.exc_info())
path = tempfile.mkstemp(suffix='html')[1]
open(path, 'w').write(response.content)
@zbyte64
zbyte64 / forms.py
Created Feb 2, 2013
Example of using Django forms to load CSVs
View forms.py
from simplecart.discounts.models import *
from simplecart.orders.models import SKU
from decimal import Decimal
import datetime
from django import forms
class r(str):
pass
@zbyte64
zbyte64 / fix_s3_crossorigin.py
Last active Dec 14, 2015
Fix cross origins on S3 with boto
View fix_s3_crossorigin.py
from boto.s3.cors import CORSConfiguration
from boto.s3.connection import S3Connection
conn = S3Connection('<aws access key>', '<aws secret key>')
bucket = conn.create_bucket('mybucket')
config = CORSConfiguration()
config.add_rule(allowed_method=['GET'], allowed_origin=['*'], allowed_header=['Content-*', 'Host'], max_age_seconds=3000)
bucket.set_cors(config)
@zbyte64
zbyte64 / gist:6453850
Created Sep 5, 2013
Cleans up test accounts
View gist:6453850
from gevent import monkey; monkey.patch_all()
from gevent.pool import Pool
import stripe
to_delete = list()
pool = Pool(10)
def check_customer(customer):
if customer['subscription'] or customer['default_card']:
return False
View story1.py
import io
numbers = {
(' _ ', '| |', '|_|'): 0,
(' ', ' |', ' |'): 1,
(' _ ', ' _|', '|_ '): 2,
(' _ ', ' _|', ' _|'): 3,
(' ', '|_|', ' |'): 4,
(' _ ', '|_ ', ' _|'): 5,
@zbyte64
zbyte64 / alpaca-om.cljs
Created Jan 16, 2014
Render alpacajs form in OM (clojsurescript react.js library); AKA render raw html in OM
View alpaca-om.cljs
(defn show-form [data _]
(om/component
(let [schema (:current-form data)
alpaca-html (.html (.alpaca (js/jQuery. "<div/>") (clj->js {:schema schema})))
form-html (js/React.DOM.div (clj->js {:dangerouslySetInnerHTML {:__html alpaca-html}}))]
form-html)))
@zbyte64
zbyte64 / tdd.rst
Created Mar 5, 2014
Testosterone Driven Development [TDD]
View tdd.rst

A compilation of software development techniques using Steve Ballmer as a mentor. Feel free to fork & add.

http://www7.pcmag.com/media/images/238533-conference-speaker-steve-ballmer.jpg

@zbyte64
zbyte64 / guideline.rst
Last active Sep 15, 2016
React.js Component Guideline
View guideline.rst

React.js Minimal Entropy Guide

DO's:

  • Use explicit contracts to pipe data & events between systems
  • Business rules should bubble towards the top, UI and semantics should sink towards the bottom

DONT's:

@zbyte64
zbyte64 / cloneComponent.js
Created May 30, 2014
Deep cloning of react components
View cloneComponent.js
var _ = require('lodash');
function isComponent(obj) {
//ghetto check because JS
return (obj && obj.setState)
}
function deepCloneComponent(tpl) {
if (!tpl) return;
if (_.isArray(tpl)) {
@zbyte64
zbyte64 / sslauth.py
Created Jun 21, 2014
Attempt to grab peer certificate when serving
View sslauth.py
from OpenSSL import crypto, SSL
from socket import gethostname
import socket
import os
import re
from pprint import pprint
from time import gmtime, mktime
from os.path import exists, join