Skip to content

Instantly share code, notes, and snippets.

@nikolajbaer
nikolajbaer / gist:193847
Created September 25, 2009 21:08
San Diego Surf Report script for Android Scripting
"""Display the (scraped) surf report for San Diego from the noaa in a notification."""
__author__ = 'Nikolaj Baer <nkolaj.baer@gmail.com>'
__copyright__ = 'Copyright (c) 2009'
__license__ = 'MIT License'
import urllib,re
LOCATION="San Diego"
AREA="SGX"
REPORT_URL="http://newweb.wrh.noaa.gov/sgx/print_version.php?sid=%s&pil=SRF&version=0"%AREA
@nikolajbaer
nikolajbaer / gist:778800
Created January 13, 2011 23:03
Litttle jquery js script to create subtotals and totals for columns in a table. Essentially tag the col "td"s that you want to sum with the class sum, mark the col "td"s that you want to be subtotals with the class "subtotal", and mark the total row as cl
<html><head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
function tally (selector) {
$(selector).each(function () {
var total = 0,
column = $(this).siblings(selector).andSelf().index(this);
$(this).parents().prevUntil(':has(' + selector + ')').each(function () {
@nikolajbaer
nikolajbaer / index.html
Created September 30, 2011 20:41
Embedded JSON per HTML Elements
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("script[type='application/json']").each(function(){
if(this.attributes["data-wc-name"]!=undefined){
var name = this.attributes["data-wc-name"].value; var o = JSON.parse(this.textContent);
this.parentElement[name]=o;
}
@nikolajbaer
nikolajbaer / copy_buckets.py
Last active October 21, 2015 04:45
Sync over S3 buckets
from boto.s3.connection import S3Connection as Connection
import sys,time,threading
source, destination = sys.argv[1:]
srcconnection = Connection()
dstconnection = Connection()
source = srcconnection.get_bucket(source)
destination = dstconnection.lookup(destination) or dstconnection.create_bucket(destination)
@nikolajbaer
nikolajbaer / manage_certs.py
Created September 24, 2012 22:53
Delete a cert from Amazon
#!/usr/bin/python
# Usage: python manage_certs.py <ACCESS KEY> <SECRET KEY> <cert name to delete>
# NOTE: your access key user must have full EC2 Permissions and IAM permissions to run this
# NOTE: This script DELETES stuff, so make sure you read through it and think twice before saying "yes" when it prompts you!
from boto.iam.connection import IAMConnection
import boto
import sys,time,threading
import optparse
@nikolajbaer
nikolajbaer / apiorm.js
Created October 7, 2012 19:38
API adapter for tastypie API
// Integrates to Web Cube Enterprise 4.2.4 API
var API = function(api_base){
var _api_base = api_base;
var _api = this;
/* utility function for ajax json request */
var make_request = function(args,api_resource_path,ajax_callback,method,data){
var parameters = "";
if(method == undefined){ method="GET"; }
@nikolajbaer
nikolajbaer / ajaxnavdemo.php
Last active December 18, 2015 23:48
JS/PHP example for loading in snippets of a page to make a nav structure ajaxable
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">
var d = null;
$(document).ready(function(){
$("li").click(function(e){
var url=$(this).data("ajax-target")
var tempDiv = $("<div />");
tempDiv.load(url,function(){
@nikolajbaer
nikolajbaer / gist:5906027
Created July 2, 2013 01:03
Example of using Multicast socket to exchange datagrams
import java.net.MulticastSocket;
import java.lang.Thread;
import java.net.InetAddress;
import java.net.DatagramPacket;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.net.UnknownHostException;
public class Client extends Thread {
@nikolajbaer
nikolajbaer / build_template.py
Created September 26, 2013 20:47
converts a vertical image of a surfboard shape to a set of horizontal 1/2 size PDF pages ... using it to make a template for an alaia i am shaping in my garage
import Image,ImageDraw,optparse,pyPdf,math
parser = optparse.OptionParser()
parser.add_option("--width",action="store",dest="width",default=20,help="width of target board in inches",type="int")
parser.add_option("--paperwidth",action="store",dest="paperwidth",default=8,help="width of target image on paper",type="int")
parser.add_option("--dpi",action="store",dest="dpi",default=72,help="target dpi resolution",type="int")
(options,args) = parser.parse_args()
DPI = options.dpi
@nikolajbaer
nikolajbaer / wc_blast.py
Last active August 29, 2015 14:03
World Cup Automatic Goal Celebration
# Use with this mp3 downloaded and renamed as "airhorn.mp3"
# http://www.freesound.org/people/mcpable/sounds/131930/
#
import urllib,json,os,sys,time
goals = []
while True:
sys.stdout.write(".")
sys.stdout.flush()
data = urllib.urlopen("http://worldcup.sfg.io/matches/today").read()