Skip to content

Instantly share code, notes, and snippets.

View amites's full-sized avatar

Alvin Mites amites

View GitHub Profile
@amites
amites / clear_django_sessions.py
Created February 16, 2011 01:03
Simple script to clear database sessions in a django project.
import MySQLdb
host = 'localhost'
user = 'USER'
passwd = 'PASSWORD'
database = raw_input('Enter database name:')
conn = MySQLdb.connect (host=host, user=user, passwd=passwd, db=database)
@amites
amites / qsolve360
Created December 23, 2011 00:21
Simple method for connecting to Solve360 API
import base64
import httplib
import logging
import string
try:
import simplejson as json
except ImportError:
import json
class settings:
@amites
amites / qsolve360
Created December 23, 2011 00:21
Simple method for connecting to Solve360 API
import base64
import httplib
import logging
import string
try:
import simplejson as json
except ImportError:
import json
class settings:
@amites
amites / model_util.py
Created January 8, 2012 06:27
Django TemplateTag to Return Filename without Directory Information
from django import template
register = template.Library()
@register.filter
def fileNameClean(file, arg):
'''
Return the file name without any directory information.
'''
obj = getattr(file, arg, False)
@amites
amites / findIP.py
Created May 25, 2012 07:44
find public ip using python (executable)
!#/usr/bin/python
# simple python script to return your public IP address using whatismyip.com
# if executed from command line will display IP
def findIP():
'''
Returns your IP address. Includes setting the header to match the request
see http://www.whatismyip.com/faq/automation.asp
'''
@amites
amites / add-ip-ec2.py
Created May 25, 2012 07:50
python add current IP address to ec2
#!/usr/bin/python
import urllib2
from boto.ec2.connection import EC2Connection
try:
from django.conf import settings
except ImportError:
class settings:
adjust_timeout () {
cat <<EOF
if keystatus --shift; then
set timeout=-1
else
set timeout=0
fi
EOF
}
@amites
amites / gimp-to-css.py
Created September 12, 2012 08:39
Convert Gimp Palette to SCSS vars
# coding: utf-8
import re
## quick hack to convert gimp color palettes into scss vars
## ended up getting rather complex when I started making it more dynamic
## may clean up in the future as proper functions with command line option
## title will be written as title_basetitle_sub[loop#]
## allows customization of title that could be extended into a config
@amites
amites / center_geo.py
Last active October 15, 2021 23:14
Center Geolocations
from math import cos, sin, atan2, sqrt
def center_geolocation(geolocations):
"""
Provide a relatively accurate center lat, lon returned as a list pair, given
a list of list pairs.
ex: in: geolocations = ((lat1,lon1), (lat2,lon2),)
out: (center_lat, center_lon)
"""
x = 0
@amites
amites / DHTtester1.ino
Last active December 10, 2015 00:49
Combined 2 example scripts with a bit of scripting to publish sensor data from 2 DHT11 sensors to a remote web-server using a GET request webClient_dht -- doesn't work with error code in comments below webClient -- works to post to web-server using a GET request DHTtester1 -- works to read sensor data and concatenate floats to a string and retur…
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
#include "DHT.h"
#define DHTPIN 2 // what pin we're connected to
#define DHTPIN2 3 // what pin we're connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11