Skip to content

Instantly share code, notes, and snippets.

@twaddington
twaddington / gist:2069215
Created March 18, 2012 05:39
Geoloqi Android SDK: Simple POST Request
if (mService != null) {
LQSession session = mService.getSession();
// Build your request
try {
JSONObject geonote = new JSONObject();
geonote.put("text", "Test!");
geonote.put("latitude", 45.5037078163837);
geonote.put("longitude", -122.622699737549);
geonote.put("radius", 467);
@twaddington
twaddington / gist:2069153
Created March 18, 2012 05:27
Geoloqi Android SDK: POST Request
// After binding to the tracking service you can
// perform a simple POST request using the runAPIRequest
// method.
//
// We'll be updating the SDK to provide simpler runGetRequest
// and runPostRequest methods to abstract away some of this
// logic.
if (mService != null) {
LQSession session = mService.getSession();
<!-- Server side code here -->
<?php
if ($_POST['action'] === 'logout') {
logout();
}
?>
<!-- Client side code here -->
<form action="" method="post">
<input type="hidden" name="action" value="logout" />
@twaddington
twaddington / copy_icons.sh
Created December 9, 2011 01:01
Find script for copying matched filenames.
find ~/android-sdk-mac_x86/platforms/ -type f \( -name "ic_menu_crop.png" -o -name "ic_menu_preferences.png" -o -name "ic_menu_share.png" -o -name "ic_menu_delete.png" -o -name "ic_menu_home.png" -o -name "ic_menu_refresh.png" \) | cp `grep -i "7.*ldpi"` .
@twaddington
twaddington / getInstanceLength.java
Created November 8, 2011 01:18
Simple method to parse an HttpResponse for a Content-Range header and extract the instance length (total size). Great for making partial-content requests.
/**
* <p>This method checks an HttpResponse for a Content-Range
* header and, if present, attempts to parse the instance-length
* from the header value.</p>
* <p>{@link http://tools.ietf.org/html/rfc2616#section-14.16}</p>
*
* @param response
* @return the total number of bytes for the instance, or a negative number if unknown.
*/
public static long getInstanceLength(HttpResponse response) {
@twaddington
twaddington / AppleVolumes.default
Created July 22, 2011 02:20
Netatalk Time Machine Config
# This line goes in /etc/netatalk/afpd.conf
- -tcp -noddp -uamlist uams_guest.so,uams_dhx.so,uams_dhx2.so -nosavepassword
# The remaining lines go in /etc/netatalk/AppleVolumes.default
# The line below sets some DEFAULT, starting with Netatalk 2.1.
:DEFAULT: options:upriv,usedots
# Regular AFP share
/mnt/storage "Storage" cnidscheme:dbd options:usedots,upriv
@twaddington
twaddington / csv.class.php
Created June 3, 2011 07:54
Basic class for serializing PHP arrays in a csv format.
<?php
class CSV {
protected $data;
/*
* @params array $columns
* @returns void
*/
public function __construct($columns) {
$this->data = '"' . implode('","', $columns) . '"' . "\n";
@twaddington
twaddington / naiveStringSearch.py
Created June 1, 2011 04:53
A naive string searching algorithm
def search(needle, haystack, end=False):
"""
A naive string searching function.
"""
n = len(needle)
h = len(haystack)
start = 0
offset = n
@twaddington
twaddington / search.js
Created May 26, 2011 19:26
Search a string for a substring
function search(str1, str2) {
var i,n;
for (i=0; i<str2.length; i++) {
for (n=0; n<str1.length; n++) {
var c1 = str1.charAt(n);
var c2 = str2.charAt(i+n);
if (c1 === c2) {
if (n === (str1.length-1)) {
return i;
}
@twaddington
twaddington / web-dev-apt.sh
Created March 28, 2011 06:31
Install web developer packages on Debian/Ubuntu using Apt.
!#/bin/bash
##
# Install requirements for Apache2, MySQL, PHP, Django, Rails
# on Debian/Ubuntu.
##
sudo apt-get install \
apache2 \
apache2-doc \
apache2-suexec \
sqlite3 \