Skip to content

Instantly share code, notes, and snippets.

View jacoby's full-sized avatar
🌮
I ❤️ Tacos

Dave Jacoby jacoby

🌮
I ❤️ Tacos
View GitHub Profile
@jacoby
jacoby / Redis Perl Sample Code.pl
Created December 14, 2012 19:54
I got complex data structures working with Redis and Perl. If you can't store complex data structures, why even deal with Redis?
#!/usr/bin/perl
# http://search.cpan.org/~dpavlin/Redis-0.0801/lib/Redis.pm
use 5.010 ;
use strict ;
use warnings ;
use Data::Dumper ;
use Redis ;
{
# Using the data
@jacoby
jacoby / fitibit_battery.py
Created February 7, 2013 17:38
Simple program to read battery information and last synchronization from my FitBit device. Amongst the bugs: Only reads one device, hardcoded consumer key and secret. But an early working piece of Python code, adapted from https://groups.google.com/forum/#!msg/fitbit-api/CkXQ6-0-vMs/VaX_V6gm3BUJ.
#!/usr/bin/env python
'''
Description:
Using the FitBit API get the device info
then, put it into the Redis NoSQL database for other programs to check
Displays:
<?xml version="1.0" encoding="UTF-8"?><result><summary><activeScore>44</activeScore><caloriesOut>1894</caloriesOut><distances><activityDistance><activity>total</activity><distance>0.11</distance></activityDistance><activityDistance><activity>tracker</activity><distance>0.11</distance></activityDistance><activityDistance><activity>loggedActivities</activity><distance>0</distance></activityDistance><activityDistance><activity>veryActive</activity><distance>0</distance></activityDistance><activityDistance><activity>moderatelyActive</activity><distance>0.03</distance></activityDistance><activityDistance><activity>lightlyActive</activity><distance>0.08</distance></activityDistance><activityDistance><activity>sedentaryActive</activity><distance>0</distance></activityDistance></distances><fairlyActiveMinutes>7</fairlyActiveMinutes><lightlyAct
@jacoby
jacoby / gist:4755471
Created February 11, 2013 16:17
This is how you send a function zero or one arguments in Python
def yaml_test( *args ):
config = '~/twitter.cnf'
assert 0 <= len(args) < 2
if len(args)==1:
config = args[0]
do_yaml( config )
@jacoby
jacoby / gist:4756753
Created February 11, 2013 19:10
Module for accessing FitBit data using Python. Current functions use JSON to handle the exported data, but XML parsing could be added in.
#!/usr/bin/env python
'''
Probably don't need the hashbang here. Leaving it anyway.
This is a module that creates a FitBit access class. This is the most
in-depth Python coding I've ever written.
This is based on sample code I found in a forum online, so I pass on this
@jacoby
jacoby / gist:4948549
Last active December 13, 2015 17:29
My attempt to make a wrapper for MySQLdb. Changed to handle my new thing of using a .my.yaml file to hold DB configuration
#!/usr/bin/env python
import sys
import yaml
import MySQLdb as db
class Database:
config = ''
def __init__( self , client="default" ):
@jacoby
jacoby / test.cgi
Created February 15, 2013 19:55
TIL that you can have query strings without query strings. Man, I wish I knew this a decade ago.
#!/usr/bin/perl
use strict ;
use warnings ;
use 5.010 ;
use CGI ;
use CGI::Carp qw( fatalsToBrowser ) ;
use Data::Dumper ;
use lib '/home/ltl/lib' ;
use LTLcommon qw{ pi_Readfile } ;
@jacoby
jacoby / gist:4979796
Last active December 13, 2015 21:48
From Database to exported PNG with R.
require( sqlutils )
require( RMySQL )
library( Cairo )
library( yaml )
my.cnf = yaml.load_file( '~/.my.yaml' )
default = my.cnf$clients$default
p_cols <- c( "blue" , "red" , "orange" , "green" )
con <- dbConnect(
@jacoby
jacoby / qc.js
Created February 21, 2013 19:03
When given an interger (which, yes, I probably need to check against), I create that many DIVs filled with FIELDSETs full of input stuff.
// --------- --------- --------- --------- --------- --------- ---------
// function to dynamically create a large number of sample fields
// --------- --------- --------- --------- --------- --------- ---------
function create_new_samples ( n ) {
for ( var i = 1 ; i <= n ; i++ ) {
$( '<div\>')
.attr( 'id' , 'div_' + i )
.appendTo( '#sample_dump' )
.append(
$( '<fieldset/>' )
@jacoby
jacoby / Beats.pm
Last active December 14, 2015 19:09
Beats.pm, a quick and dirty module to convert times to Swatch Internet Time. http://en.wikipedia.org/wiki/Swatch_Internet_Time
package Beats ;
use strict ;
use warnings ;
use Exporter qw(import) ;
use DateTime ;
our $VERSION = 0.0.1 ;
our @EXPORT = qw( time_in_beats ) ;
@jacoby
jacoby / MyDB.pm
Created March 13, 2013 16:09
Perl Module for abstract access to MySQL DB
package MyDB ;
=head1 NAME
MyDB - Module handling access to MySQL databases
=head2 DESCRIPTION
Mostly used within DB.pm, which handles the actual queries. This handles
connecting to the actual databases.