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
//scala DI API | |
object MyContainer extends Container with GuiceSupport with ServletSupport{ | |
configure(bind:BinderWrapper) { | |
val something = provide[Frog] { | |
if (Math.random() > .5) { | |
frogMan | |
} else weaselGirl | |
} | |
val onOff = bindTo[Heater] | |
val sensor = bindTo[Sensor] |
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
// show cookies for current site - bookmarklet | |
javascript:(function(){x=window.open();x.document.write('%3Cht'+'ml%3E/r%3Che'+'ad%3E%3Ctitle%3EDisplay%20Cookies%3C/title%3E%3C/he'+'ad%3E%3Cbo'+'dy%3E');if%20(document.cookie%20==%20'')%20x.document.write('No%20Cookies%20Found');%20else%20{thisCookie%20=%20document.cookie.split(';%20');%20for%20(i=0;%20i%3CthisCookie.length;%20i++)%20{x.document.write(thisCookie[i]%20+%20'%3Cbr%20//%3E');}}x.document.write('%3C/bo'+'dy%3E%3C/ht'+'ml%3E');x.document.close();})() | |
//delete cookies for current site - bookmarklet | |
javascript:(function(){C=document.cookie.split("; ");for(d="."+location.host;d;d=(""+d).substr(1).match(/\..*$/))for(sl=0;sl<2;++sl)for(p="/"+location.pathname;p;p=p.substring(0,p.lastIndexOf('/')))for(i in C)if(c=C[i]){document.cookie=c+"; domain="+d.slice(sl)+"; path="+p.slice(1)+"/"+"; expires="+new Date((new Date).getTime()-1e11).toGMTString()}})() |
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
phausel@kola ~/workspace/akka | |
$ sbt package | |
[info] Building project akka 0.7-SNAPSHOT against Scala 2.7.7 | |
[info] using AkkaParent with sbt 0.7.1 and Scala 2.7.7 | |
[info] | |
[info] == akka-java-util / compile == | |
[info] Source analysis: 12 new/modified, 0 indirectly invalidated, 0 removed. | |
[info] Compiling main sources... | |
[error] Note: /Users/phausel/workspace/akka/akka-util-java/src/main/java/se/scalablesolutions/akka/config/ActiveObjectGuiceModule.java uses unchecked or unsafe operations. | |
[error] Note: Recompile with -Xlint:unchecked for details. |
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; | |
/** | |
* simply utility to deal with files, it's depending on IOUtilities | |
* | |
*/ | |
public class FileUtilities { | |
// charsetName can be null to use the default charset. |
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
@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); |
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 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.*; |
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 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 |
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 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); |
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
//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); | |
} | |
} |
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 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 |
OlderNewer