View gist:1104424
# enumerate all subsequences in a sequence
def subsequences(s):
for i in range(len(s)):
for j in range(len(s) - i):
yield s[j:j + i + 1]
if __name__ == '__main__':
assert list(subsequences([])) == []
assert list(subsequences([1])) == [[1]]
View gist:1104429
# UPnP Port Mapper
import os
import sys
import re
import urllib2
from xml import sax
from xml.sax import handler
from xml.sax.handler import feature_namespaces
import socket
View gist:1104608
// connect system call with blocking timeout.
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
View Unzip.java
import java.io.File;
import java.io.InputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class Unzip {
View gist:1604340
import java.io.File;
import java.io.IOException;
public class Rmr {
public static void rmr(String path) {
File target = new File(path);
rmr(target);
}
View gist:1670883
public static float applyDimension(int unit, float value,
DisplayMetrics metrics)
{
switch (unit) {
case COMPLEX_UNIT_PX:
return value;
case COMPLEX_UNIT_DIP:
return value * metrics.density;
case COMPLEX_UNIT_SP:
return value * metrics.scaledDensity;
View ZipCursor.java
import android.database.AbstractCursor;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.DataSetObserver;
public class ZipCursor extends AbstractCursor {
private DataSetObserver default_observer = new DataSetObserver() {
@Override
View SplitCursor.java
import android.database.AbstractCursor;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.DataSetObserver;
public class SplitCursor extends AbstractCursor {
private DataSetObserver default_observer = new DataSetObserver() {
@Override
public void onChanged() {
View abspath.sh
#!/bin/sh
THIS=${0#$(dirname $0)/}
echo $PWD/$THIS
View gist:2836138
private boolean isMain() {
boolean result = false;
Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
List<ResolveInfo> info = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (!info.isEmpty()) {
result = info.get(0).activityInfo.name.equals(getComponentName().getClassName());
}
return result;