Skip to content

Instantly share code, notes, and snippets.

View apiguy's full-sized avatar

Freedom Dumlao apiguy

View GitHub Profile

Keybase proof

I hereby claim:

  • I am apiguy on github.
  • I am apiguy (https://keybase.io/apiguy) on keybase.
  • I have a public key whose fingerprint is B007 ED9E C641 A8C8 BDAA 3EE0 1BAF 9671 E675 C159

To claim this, I am signing this object:

@apiguy
apiguy / float-issue.py
Created October 29, 2013 21:10
Demonstrates how floats can be inaccurate
time = .0
seconds = 0
while True:
time += .1
seconds = int(time)
print "---------------"
print "Time to str: ", time
print "Time to int: ", int(time)
print "Seconds: ", seconds
@apiguy
apiguy / case_sensitivity_perf_test.py
Last active December 19, 2015 16:39
Comparison of performance of case sensitivity comparisons in python
import timeit
setup = """
import re
from itertools import ifilter
x = "active"
regex = re.compile(x, re.IGNORECASE)
def uppertest():
@apiguy
apiguy / if_filter.py
Last active December 19, 2015 07:28
If template filter for Jinja2
def if_(value, truth_test):
return value if truth_test else None
# Usage
"""
{{ active|if_(row.first) }}
"""
#!/bin/bash
###############################################
# To use:
# https://raw.github.com/gist/2776351/???
# chmod 777 install_postgresql.sh
# ./install_postgresql.sh
###############################################
echo "*****************************************"
echo " Installing PostgreSQL"
echo "*****************************************"
#!/bin/bash
redis_version=2.6.13
# from here: http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/
# and here: https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server
###############################################
# To use:
# wget https://gist.github.com/apiguy/5669466/raw/952b5221f46db37d1cda8fb04c6a23356b9c6338/install-redis.sh
# chmod +x install-redis.sh
# ./install-redis.sh
@apiguy
apiguy / gist:5632134
Created May 23, 2013 01:12
Fine grained Flask-Classy cache header example
class BlogView(FlaskView):
cacheable_views=('index')
def index(self):
return render_template('index.html')
def get(self, id):
return render_template('get.html')
@apiguy
apiguy / grouper.py
Created April 24, 2013 17:57
Grouping strings by prefixes in python
#!/usr/bin/env python
# Gribouillis at www.daniweb.com
"""
The class Grouper implements grouping strings by prefixes.
A Grouper object is created with a sequence of prefixes
G = Grouper(["pref1", "pref2", ...])
(an empty prefix is automatically added). The Grouper object
is a dictionary "prefix --> set of strings". Initially, it looks
like
{
@apiguy
apiguy / gist:4660026
Created January 28, 2013 22:47
Super basic way to get a wsgi app running on cherrypy with autoreload. Useful for development and testing.
import cherrypy
from main import app
cherrypy.config.update({'server.socket_host': '0.0.0.0',
'server.socket_port': 8080})
cherrypy.tree.graft(app)
if __name__ == '__main__':
try:
cherrypy.engine.start()