Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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"` .
<!-- 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 / 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();
@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);
# Loop over each object and either update or create.
try:
obj = MyObject.objects.get(pk=id)
obj.value1 = 1
obj.value2 = 2
except MyObject.DoesNotExist:
obj = MyObject(value1=1, value2=2, ...)
# Update the object
time = "10 minutes ago"
if ((distance_moved *since* time) < 200):
# Possibly return a 420 or 429 response code? Possibly not a 429,
# since we might want to use that for actual API request rate limiting.
#
# http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#420
response = {
"error": "back_off",
"error_message": "...",
"latitude": 125.45,
LQSession session = mService.getSession();
// Get the current user's profile
session.runGetRequest("account/profile", new OnRunApiRequestListener() {
@Override
public void onSuccess(LQSession session, HttpResponse response) {
// Consume the response!
// ...
JSONObject json = new JSONObject(EntityUtils.toString(response.getEntity()));
}
public classd MyActivity extends Activity implements OnClickListener {
private LQService mService;
private boolean mBound;
private SampleReceiver mLocationReceiver = new SampleReceiver();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}