Skip to content

Instantly share code, notes, and snippets.

@python1981
python1981 / gist:e2843b5b9af98d92732c
Created September 2, 2014 03:23
IRR formula for PHP
<?php
class IRRHelper{
//Adapted from Javascript version here: https://gist.github.com/ghalimi/4591338
//
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
//
// Some algorithms have been ported from Apache OpenOffice:
//
@python1981
python1981 / gist:5333e629a10f3a8c8526
Last active October 15, 2015 01:45
Convert PHP to Python (incomplete time-saver)
#Instructions:
# 1. Launch ipython
# 2. manually set filename = '/path/to/file.php'
# 3. Copy/Paste the below code to write transformed content to ./output.txt
import re
with open(filename,'r') as f: code = f.read()
code = code.replace('<?php','').replace('<?','')
@python1981
python1981 / gist:0e7375de0b41bd15197e
Created November 19, 2015 12:30
Convert input_60fps.mov to output_20fps.mov
ffmpeg -i input_60fps.mov -f rawvideo -pix_fmt yuv420p -vcodec rawvideo -y pipe:1 | ffmpeg -r 60 -f rawvideo -pix_fmt yuv420p -r 60 -s 1280x800 -i - -vf framestep=3 -y output_20fps.mov
@python1981
python1981 / show_licenses_for_requirements.py
Created January 16, 2016 06:00
Show licenses for all packages in requirements.txt
#Usage: python show_licenses_for_requirements.py ./requirements.txt
# Setup:
# pip install requirements-parser
import sys
import pkg_resources
import requirements
def get_modules(requirements_file_path):
@python1981
python1981 / gist:25cb7c462e5d96b5ad9257c476a24b0f
Created March 8, 2017 04:34
Save Alexa response to ogg audio file
# Manual steps initially:
# 1. Use the Alexa developer console "Test" mode to test your phrase
# 2. View NETWORK DEBUG panel, find the "getTTS" POST request, right-click and "Save as HAR with content" to a file called 'get_tts.txt'
# 3. Run the code below to convert to audio file 'audio.ogg'
import urllib
import json
import base64
with open('tts.txt','r') as f:
@python1981
python1981 / gist:ffeb3725b977b6c36f5c8e038c7e8f35
Created September 2, 2020 16:26 — forked from kipanshi/gist:4007717
Django float format and intcomma optimization
import cProfile
from django.template.defaultfilters import floatformat as floatformat_django
from django.contrib.humanize.templatetags.humanize import intcomma as intcomma_django
num = 100000
float_num = 1 / 3.0
def floatformat(value, places=2):