Skip to content

Instantly share code, notes, and snippets.

View zinking's full-sized avatar

zhen zinking

  • dalab
  • 中国
View GitHub Profile
file=$1
fdir=$(dirname "$file")
fbar=$(basename "$file")
ffoo=$(basename "$fdir")
echo "$fdir $fbar $ffoo"
fdcmd="cd /data/tdwadmin/zhnwang/dataware/$ffoo"
sdcmd="deploy $fbar $fbar -f"
@zinking
zinking / sobject.scala
Created September 26, 2021 02:30
reflective call SCALA [object] method
import scala.reflect.runtime.universe._;
import org.apache.spark.sql.SparkSession;
val field = spark.getClass.getDeclaredField("extensions");
field.setAccessible(true);
val extensions = field.get(spark).asInstanceOf[org.apache.spark.sql.SparkSessionExtensions];
val tpe = typeOf[org.apache.spark.sql.SparkSession];
val m = scala.reflect.runtime.currentMirror;
val im = m.reflect(m.reflectModule(tpe.typeSymbol.asClass.companion.asModule).instance);
val method = tpe.companion.decl(TermName("applyExtensions")).asMethod;\n
im.reflectMethod(method)("io.delta.sql.DeltaSparkSessionExtension" :: Nil, extensions);
var dispatchMouseEvent = function(target, var_args) {
var e = document.createEvent("MouseEvents");
// If you need clientX, clientY, etc., you can call
// initMouseEvent instead of initEvent
e.initEvent.apply(e, Array.prototype.slice.call(arguments, 1));
target.dispatchEvent(e);
};
function clickContinue() {
dispatchMouseEvent(element, 'mouseover', true, true);
@zinking
zinking / GarbageTest.java
Created August 24, 2016 13:01
useless throw POC
//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();
}
#!/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
@zinking
zinking / Java.Apache.HttpClient.MakeRequest
Created April 13, 2016 06:39
Java Apache HttpClient make request
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();
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
@zinking
zinking / disqus-python.py
Last active August 29, 2015 13:57
python disqus usage
ps = d.disqus.posts.list(forum='campusnews')
#likes / dislikes
rs = d.disqus.posts.details( post='1310432214')
@zinking
zinking / lisp.el
Created January 20, 2014 02:12
some lisp tips
(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)
@zinking
zinking / faq.py
Last active January 1, 2016 23:08
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) )