Skip to content

Instantly share code, notes, and snippets.

@jiaaro
jiaaro / timings.py
Created May 6, 2015 23:12
ujson timings
# 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 17:27
Make a chord progressions
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 August 29, 2015 14:25
formset example code
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):
...
<script>
// using jQuery
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
@jiaaro
jiaaro / _INSTRUCTIONS.md
Last active January 22, 2024 17:47
Using Swift libraries in Python

Using Swift libraries in Python

So... this is obviously totally, 100%, like for. real. not. supported. by. Apple. …yet?

But still... I thought it was pretty badass. And, seeing how there's already a Swift buildpack for Heroku you could move some slow code into Swift can call it as a library function. But, you know, not in production or anything. That would be silly, right?

Now, having said that, the actual Python/Swift interop may have bugs. I'll leave that as an exercise to the reader.

How to get Python code calling Swift functions:

@jiaaro
jiaaro / organism.py
Last active January 4, 2016 18:36
NOTE: organism.py belongs in a directory "breeder"
#!/usr/bin/env python
import ast
from os.path import isfile
from hashlib import md5
from random import randint, choice
from glob import glob
import re
# scratch area
"""
@jiaaro
jiaaro / investment_calculator.py
Last active March 16, 2016 04:18
Calculate the value of your investments and savings at some point in the future
class Investment(object):
def cash_invested_by_month(self, month):
raise NotImplementedError
def value_in_month(self, month):
raise NotImplementedError
class SingleInvestment(Investment):
def __init__(self, amount, monthly_interest_rate, month=0):

Keybase proof

I hereby claim:

  • I am jiaaro on github.
  • I am jiaaro (https://keybase.io/jiaaro) on keybase.
  • I have a public key ASAmjWlR2gGlcJGuKzzPQ4UDqxXW0WeP-NDoJACLKWKo7go

To claim this, I am signing this object:

If you've ever wondered what it's be like to "go indie" here is a script with some assumptions that might help you project your income.

Assumptions:

  • You will make a new app every month
  • Apps have a useful life of 3 years (after that they stop earning money)
  • Apps will earn $250 in their launch month
  • Apps will earn $100/mo at first (starting month 2), but that revenue will slowly decline (~50% each year)
  • As you make more apps your brand/mailing list will start to pay dividends (after 4 apps you'll see the numbers above double, after 8 they'll 3x, and so on)

So how would that work out?

In [1]: paste
import array
from pydub import AudioSegment
from pydub.generators import Sine, Square
# make two mono sounds (300 Hz tones)
sound1 = Sine(300).to_audio_segment(duration=30000)
sound2 = Square(300).to_audio_segment(duration=30000)
def x():