Skip to content

Instantly share code, notes, and snippets.

@jiaaro
jiaaro / marco_arment.py
Created Mar 7, 2014
Marco Compatibility
View marco_arment.py
import warnings
import random
if random.random() > 0.999:
warnings.warn("Hi marco, nice day today, eh?")
@jiaaro
jiaaro / exploit.js
Created May 29, 2014
XSS Game level 6
View exploit.js
alert('adsf')
@jiaaro
jiaaro / conv.py
Last active Aug 29, 2015
create hstore col
View conv.py
from django.db import connection
def hs_str(s):
s = unicode(s)
return s.replace('"', r'\"')
def dict_to_hstore(d):
hs_data = [u'"{0}" => "{1}"'.format(hs_str(k), hs_str(v)) for (k, v) in data.items()]
hs_data = u",".join(hs_data)
return "u'{0}'::hstore".format(hs_data)
@jiaaro
jiaaro / gist:fda3d04cf76f49f8051e
Created Aug 6, 2014
app revenue calculations
View gist:fda3d04cf76f49f8051e
Development time: 3 weeks (15 * 8 == 120 hours)
Marketing time: 2 weeks (10 * 8 = 80 hours)
hourly: $200 (must pay well enough to justify risk)
profit target: $40k (200 hrs * $200)
revenue target: $60k (40000 / 0.67, Apple's cut)
--------
@jiaaro
jiaaro / splitstereo.sh
Created Aug 7, 2014
Split Stereo Files (ffmpeg)
View splitstereo.sh
#!/bin/bash
INFILE="${1}"
LFILE=$(SND="$INFILE" python -c "import os; print '{0}.L{1}'.format(*os.path.splitext(os.environ['SND']))")
RFILE=$(SND="$INFILE" python -c "import os; print '{0}.R{1}'.format(*os.path.splitext(os.environ['SND']))")
echo "Splitting $INFILE into:"
echo " LEFT: $LFILE"
echo " RIGHT: $RFILE"
echo
View solution.js
function Event() {
this.listeners = [];
}
Event.prototype.subscribe = function(fn) {
this.listeners.push(fn);
}
Event.prototype.unsubscribe = function(fn) {
for (var i = 0; i < this.listeners.length; i++) {
if (this.listeners[i] === fn) {
this.listeners.splice(i, 1);
View 0 What needs to be updated.md

MP

dashboard

  • Analysis | almost all the fields

dpm_core

  • Market | description / latest update
  • Panel | headers

homepage and sidebar features

View timings.py
# Timings taken on a MacBook Pro (Retina, 15-inch, Mid 2014)
# running OS X 10.10.3
In [1]: import sys
In [2]: print sys.version
2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)]
In [3]: data = [{str(x): y+z for x in range(10) for y in range(50)} for z in range(500)]
In [4]: import json
@jiaaro
jiaaro / chord_pregression_player.py
Created May 23, 2015
Make a chord progressions
View chord_pregression_player.py
from pydub import AudioSegment
from pydub.generators import Sine, Square, WhiteNoise
from pydub.playback import play
# From https://gist.github.com/jiaaro/339df443b005e12d6c2a
def note_to_freq(note, concert_A=440.0):
'''
from wikipedia: http://en.wikipedia.org/wiki/MIDI_Tuning_Standard#Frequency_values
'''
return (2.0 ** ((note - 69) / 12.0)) * concert_A
@jiaaro
jiaaro / forms.py
Last active Aug 29, 2015
formset example code
View forms.py
class MyForm(forms.Form):
is_interesting = forms.BooleanField(required=False)
def __init__(self, *args, **kwargs):
self.object = kwargs['initial']['obj']
super(MyForm, self).__init__(*args, **kwargs)
def save(self):
...