Skip to content

Instantly share code, notes, and snippets.

View mlc's full-sized avatar

mike castleman mlc

View GitHub Profile
@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 / 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: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 / 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: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);
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 / 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.");
@mlc
mlc / javasample.java
Created April 24, 2012 17:09
Accessing the Meetup API, setting the Accept-Charset header
public class Meetup {
public HttpResponse get(String url, List<? extends NameValuePair> params) throws IOException {
DefaultHttpClient cli = new DefaultHttpClient();
cli.addRequestInterceptor(new HttpRequestInterceptor() {
@Override
public void process(HttpRequest httpRequest, HttpContext httpContext) throws HttpException, IOException {
httpRequest.addHeader(HttpHeaders.ACCEPT_CHARSET, "utf-8");
}
});
@mlc
mlc / index.haml
Created August 3, 2011 15:39
quick barcode generation in Rails
# put into your Gemfile
gem 'chunky_png'
gem 'barby', :require => ['barby', 'barby/outputter/chunky_png_outputter']
@mlc
mlc / download-tal.sh
Created April 11, 2011 00:16
Script to download This American Life episodes.
#!/bin/sh
#
# This script downloads episodes of This American Life. It is useful
# because it downloads from the server normally use for streaming
# episodes in the flash player, so you can downoad episodes that are
# newer or older than the one currently available for podcast
# listening.
#