View GarbageTest.java
//In discussion of http://stackoverflow.com/questions/39118224/would-java-jit-compiler-optimise-useless-throw-statement
//awang:/tmp/ $ cat GarbageTest.java [20:57:30]
import java.io.IOException;
public class GarbageTest {
private void f() throws IOException {
throw new IOException();
}
View solve Einstein puzzle using Pycosat
#!/usr/bin/python
import pycosat
class Var(object):
_num_vars = 0
idx_to_var = {}
@staticmethod
def _add_var(var):
Var._num_vars += 1
idx = Var._num_vars
View Java.Apache.HttpClient.MakeRequest
public static String getAccessTokenOfAccount() throws IOException {
String url = "SOMEURL";
DefaultHttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuilder result = new StringBuilder();
View server-vagrant-setup
apt-cache search virtualbox
sudo aptitude install virtualbox-ose-dkms
wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2_x86_64.deb (#https://www.vagrantup.com/download-archive/v1.7.2.html)
dpkg -i vagrant_1.7.2_x86_64.deb
sudo dpkg -i vagrant_1.7.2_x86_64.deb
sudo apt-get install linux-headers-$(uname -r)
sudo dpkg-reconfigure virtualbox-ose-dkms
View disqus-python.py
ps = d.disqus.posts.list(forum='campusnews')
#likes / dislikes
rs = d.disqus.posts.details( post='1310432214')
View lisp.el
(defun db-compile()
"run a command on the current file and revert the buffer"
(interactive)
(shell-command
(format "RTZ.py %s"
(shell-quote-argument (buffer-file-name))))
(revert-buffer t t t))
(global-set-key (kbd "M-o M-c") 'db-compile)
View faq.py
def foo():
pass;
if __name__ == '__main__':
import timeit
print(timeit.timeit("test()", setup="from __main__ import test", number=10))
if __name__=='__main__':
from timeit import Timer
t = Timer(lambda: foo(bar) )
View faq.ksh
T=$(grep -i "Message received:" $F | wc -l)
typeset -F2 MP=$M.00/$T.00 #float number calculation
printf "Total[%8s] [%8.2f]"
#meaning escalate all warnings like 0 rows
set -e
tr '\n' ' ' | sed s/.$//' '
grep -i "message" `find 2014* -type f -name *.log` | wc -l