This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.IOException; | |
public class Rmr { | |
public static void rmr(String path) { | |
File target = new File(path); | |
rmr(target); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
THIS=${0#$(dirname $0)/} | |
echo $PWD/$THIS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
OlderNewer