Skip to content

Instantly share code, notes, and snippets.

View aaronpk's full-sized avatar

Aaron Parecki aaronpk

View GitHub Profile
from icalendar import Calendar, Event
import simplejson as json
import re
import web
from mimerender import mimerender
import sys
import urllib2
event = {}
[
{
"id": "Rh9",
"latitude": 45.524164,
"longitude": -122.67881
},
{
"id": "Rha",
"latitude": 45.52431,
"longitude": -122.67722
{
"places": [
{
"extra": {
"active": "1"
},
"latitude": "45.525467",
"longitude": "-122.678533",
"name": "8th Ave North of Everett",
"place_id": "3k2",
@aaronpk
aaronpk / anth.ro.php
Created March 25, 2011 18:45
anth.ro URL shortener
// Read more: http://neverusethisfont.com/blog/2011/03/url-shortener-as-a-search-interface/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/search?btnI=I\'m+Feeling+Lucky&q=' . urlencode($_GET['code']) . '+site%3Acyborganthropology.com');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE); // Don't follow redirects, we want the first Location header
curl_setopt($ch, CURLOPT_HEADER, TRUE); // Return the headers in the output curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla"); // Set the user agent to Mozilla so Google doesn't block the query
curl_setopt($ch, CURLOPT_NOBODY, TRUE); // Don't include the response body in the output
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Return the response in a variable instead of printing it out
$response = curl_exec($ch);
@aaronpk
aaronpk / gist:893524
Created March 29, 2011 22:51
Selectively trim text
<?php
$examples[] = 'This is text with no trim components';
$examples[] = 'This text is short but has /--trim components --/ too.';
$examples[] = 'This text is going to be quite long and has some parts that can be removed, /--such as this one, --/ and some that can\'t.';
$examples[] = 'This text is /-2-quite --/long and has some parts that can be removed, /-1-such as this one, --/ and some that can\'t.';
$trimLength = 100;
foreach($examples as $example) {
@aaronpk
aaronpk / gist:899244
Created April 2, 2011 05:02
Sending location data to the Geoloqi streaming server
require 'rubygems'
require 'socket'
socket = TCPSocket.new("stream.geoloqi.com", 40000)
puts socket.recv(100)
socket.write('your-access-token')
socket.flush
# The server outputs a confirmation message after connecting
puts socket.recv(1000)
@aaronpk
aaronpk / gist:899827
Created April 2, 2011 20:00
Retrieve the first significant sentence from a wikipedia article
<?php
$id = $_GET['id'];
function getSignificantSentence($id) {
$url = 'http://en.wikipedia.org/w/index.php?curid=' . $id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
@aaronpk
aaronpk / sql-benchmark.php
Created April 9, 2011 17:51
SQL Connect Benchmark
<?php
// Set up your database connection
define('PDO_DSN', 'mysql:dbname=test;host=127.0.0.1');
define('PDO_USER', 'root');
define('PDO_PASS', '');
/******
Output will be something like this:
@aaronpk
aaronpk / gist:911614
Created April 9, 2011 17:59
SQL Benchmark Tests
Linode 1 -> itself over 127.0.0.1:
Finished in 5136 ms
avg connect: 564 microseconds
avg prepare: 71 microseconds
avg execute: 176 microseconds
avg fetch: 4 microseconds
----
@aaronpk
aaronpk / gist:966720
Created May 11, 2011 15:48
Email beta signup form saved to Google Docs
<!-- Put this in a file called post.php -->
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://spreadsheets.google.com/formResponse?formkey=your-google-form-key');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
'entry.0.single' => date('Y-m-d H:i:s'),
'entry.1.single' => $_POST['email'],
'entry.2.single' => $ref,