Skip to content

Instantly share code, notes, and snippets.

View mlc's full-sized avatar

mike castleman mlc

View GitHub Profile
@mlc
mlc / ContractFragment.java
Created May 16, 2012 16:33 — forked from JakeWharton/ContractFragment.java
Base fragment to ensure the parent activity implements a contract interface.
/* Base fragment to ensure the parent activity implements a contract interface. */
public abstract class ContractFragment<T> extends Fragment {
private T mContract;
@Override
public void onAttach(Activity activity) {
if (!((Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0]).isAssignableFrom(activity.getClass()))
throw new IllegalStateException(activity.getClass().getSimpleName()
+ " does not implement " + getClass().getSimpleName() + "'s contract interface.");
package com.meetup.adapter;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
public class CursorPagerAdapter<F extends Fragment> extends FragmentStatePagerAdapter {
private final Class<F> fragmentClass;
@mlc
mlc / gist:3920469
Created October 19, 2012 20:20
Adding to the calendar on Android
Intent calendarIntent = new Intent(Intent.ACTION_EDIT)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setType("vnd.android.cursor.item/event")
.putExtra("beginTime", state.time)
.putExtra("endTime", state.endTime)
.putExtra("title", name)
.putExtra("description", calendarDescription)
.putExtra("eventLocation", address);
startActivity(calendarIntent);
@mlc
mlc / 10print.c
Created December 1, 2012 23:54
port of 10 PRINT to C
/*
* port of
* 10 PRINT CHR$(205.5+RND(1)); : GOTO 10
* to modern-ish C
*/
#include <locale.h>
#include <wchar.h>
#include <stdlib.h>
#include <time.h>
@mlc
mlc / gist:4222605
Created December 6, 2012 07:46
event-driven 10 PRINT program using libev
#include <ev.h>
#include <locale.h>
#include <stdio.h>
#include <wchar.h>
#include <termios.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
@mlc
mlc / README.md
Created January 5, 2013 01:57
sha1 hashing all the locations in a GeoIP database.

to try these scripts, grab the free MaxMind database, unpack, and then edit the GeoLiteCity-Location.csv file, removing the first (copyright) line.

on my laptop, the script which merely parses the data, converts to UTF-8, and then re-outputs as CSV again took 22.7 seconds of CPU time, while the script which additionally computes a SHA1 hash of the City, State (or other region), and Country took 28.7 seconds — only 6 seconds (26%) more.

you need Ruby 1.9.x, which is pretty much standard these days.

@mlc
mlc / gist:4566033
Last active December 11, 2015 07:28
generating 100 random 50000-byte files and zipping them to see if they shrink or not.
mlc@mlc:~$ for i in `seq 1 100`; do dd if=/dev/urandom bs=50000 count=1 of=blah 2>/dev/null; advzip -q4a blah.zip blah; ls -l blah.zip; rm blah blah.zip; done
-rw-rw-r-- 1 mlc users 50106 Jan 18 11:59 blah.zip
-rw-rw-r-- 1 mlc users 50106 Jan 18 11:59 blah.zip
-rw-rw-r-- 1 mlc users 50106 Jan 18 11:59 blah.zip
-rw-rw-r-- 1 mlc users 50106 Jan 18 11:59 blah.zip
-rw-rw-r-- 1 mlc users 50106 Jan 18 11:59 blah.zip
-rw-rw-r-- 1 mlc users 50106 Jan 18 11:59 blah.zip
-rw-rw-r-- 1 mlc users 50106 Jan 18 11:59 blah.zip
-rw-rw-r-- 1 mlc users 50106 Jan 18 11:59 blah.zip
-rw-rw-r-- 1 mlc users 50106 Jan 18 11:59 blah.zip
@mlc
mlc / gist:4614375
Created January 23, 2013 22:02
Is it still art if you have to explain it?
__̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡ ̡͌l̡̡̡̡.___
U+005F LOW LINE
UTF-8: 5f UTF-16BE: 005f Decimal: &#95;
_
Category: Pc (Punctuation, Connector)
Bidi: ON (Other Neutrals)
U+005F LOW LINE
UTF-8: 5f UTF-16BE: 005f Decimal: &#95;
import com.google.android.gms.maps.model.LatLng;
import com.google.common.collect.Lists;
import java.util.List;
import static java.lang.Math.*;
public class CircleMaker {
private static final double EARTH_RADIUS = 6371000.0; /* meters */
private static final int CIRCLE_PRECISION = 48;
@mlc
mlc / NfcUtils.java
Last active December 12, 2015 04:08
nfc sample
package com.meetup.utils;
import android.annotation.TargetApi;
import android.app.Activity;
import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.NfcEvent;
import android.os.Build;