Skip to content

Instantly share code, notes, and snippets.

View pk11's full-sized avatar

Peter Hausel pk11

  • Silicon Valley, CA
View GitHub Profile
@pk11
pk11 / gist:1011576
Created June 7, 2011 02:28
web plugin
resolvers += "Web plugin repo" at "http://siasia.github.com/maven2"
//Following means libraryDependencies += "com.github.siasia" %% "xsbt-web-plugin" % <sbt version>
libraryDependencies <+= sbtVersion("com.github.siasia" %% "xsbt-web-plugin" % _)
@pk11
pk11 / gist:1011562
Created June 7, 2011 02:18
sbt example
name := "myproject"
organization := "com.booo"
version := "1.0"
scalaVersion := "2.8.1"
scalacOptions += "-deprecation"
@pk11
pk11 / gist:1011545
Created June 7, 2011 02:09
sbt executable
java -Dfile.encoding=UTF8 -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -jar /opt/local/lib/sbt/sbt-launch10.jar "$@"
import static com.my.utils.FileUtilities.*;
/**
* Demonstrating how to use FileUtilities http://gist.github.com/405510
* and IOUtilities http://bit.ly/dc9vn4
**/
public void fileUtilDemo() throws java.io.IOException {
String content = readFileAsString("myfile.txt");
deleteDirectory("images"); //deletes directory recursively
//normal java
public List<Item> getTitles(Collection<Item> items,String title) {
List<Item> matching = new ArrayList<Item>();
Iterator<Item> iter = items.iterator();
while (iter.hasNext()) {
Item item = iter.next();
if (item.getTitle().equals(title)) {
matching.add(title);
}
}
import static com.my.utils.HttpHelper.*;
//Perform a GET
String response = performGet("http://mysite.com");
//do something with response
//Perform a more complex GET
Map<String,String> headers = new HashMap<String,String>();
headers.put("special","header");
String response = performGet("http://mysite.com","john","password",headers);
private static final String TAG = "MyActivity";
@As(Runnable.class)
void foo(){Log.v(TAG,announcement);}
//another example
@As(OnTabChangeListener.class)
void call(@As.Additional String param, String s) {
//do something at tab change
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import com.my.mobile.provider.HtmlContentProvider;
import android.content.ContentProvider;
import static org.powermock.api.mockito.PowerMockito.*;
@As(Runnable.class)
void feedReader() {
try {
List<String> titles = new ArrayList<String>();
//for this example, let's use a file
VTDGen vg = new VTDGen();
File f = new File("./myfeed.xml");
FileInputStream fis = new FileInputStream(f);
byte[] b = new byte[(int) f.length()];
fis.read(b);
import java.io.File;
import java.io.IOException;
/**
* simply utility to deal with files, it's depending on IOUtilities
*
*/
public class FileUtilities {
// charsetName can be null to use the default charset.