Skip to content

Instantly share code, notes, and snippets.

@yshavit
yshavit / va_elections.py
Created November 6, 2019 18:27
Vote percentage totals for VA 2019
# download file from https://results.elections.virginia.gov/vaelections/2019%20November%20General/Json/GeneralAssembly.json
import json
all_results = None
with open('va-elections.json') as f:
all_results = json.load(f)
races = all_results['Races']
votes_by_party = {}
caption always '%{= kc}screen / %{kw}%-w%{+bu ky}%n %t%{-bu kw}%+w%{kc}%-37=%{kc} CPU (1/5/15m) %l - %c'
altscreen on # also, add "export TERM=xterm" to ~/.zshrc
package com.yuvalshavit;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
@yshavit
yshavit / Chomp.hs
Created November 17, 2015 19:59
Chomps off the last newline from stdin, and outputs the result to stdout
import System.IO(getContents, putStr)
main :: IO ()
main = do stdin <- getContents
putStr (trimR stdin)
trimR :: String -> String
trimR "" = ""
trimR "\n" = ""
trimR (h:t) = h : trimR t
boolean shouldRun;
synchronized (NonSingletonActor.class) {
shouldRun = ! executed;
executed = true;
}
if (shouldRun) {
// your code here, not under synchronization
}
public class So32063820 {
public String withFinals() {
final String a = "hello ";
final String b = "world";
return a + b;
}
public String withoutFinals() {
String a = "hello ";
String b = "world";
public class Pluses {
public static void main(String[] args) {
int first = 1;
int second = 100;
System.out.println(first + + + + + + second); // 101
System.out.println(first); // 1
System.out.println(second); // 100
}
}
Traceback (most recent call last):
File "/usr/share/hubspot/mesos/slaves/20140430-110919-2712310282-5050-4748-53/frameworks/sy3x2/executors/rg941/runs/49d41680-d58e-435e-b66a-588a8766596b/content_web_proc-web-7274_293-1406223393098-1-tarly-us_east_1a/app/.deploy_virtualenv/lib/python2.6/site-packages/gevent/greenlet.py", line 327, in run
result = self._run(*self.args, **self.kwargs)
File "/usr/share/hubspot/mesos/slaves/20140430-110919-2712310282-5050-4748-53/frameworks/sy3x2/executors/rg941/runs/49d41680-d58e-435e-b66a-588a8766596b/content_web_proc-web-7274_293-1406223393098-1-tarly-us_east_1a/app/.deploy_virtualenv/lib/python2.6/site-packages/raven/transport/base.py", line 197, in send
response = compat.urlopen(req, data, self.timeout).read()
File "/usr/lib64/python2.6/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib64/python2.6/urllib2.py", line 397, in open
response = meth(req, response)
import java.lang.reflect.Modifier;
public class Ctors {
private class MyInner {
}
public static void main(String[] args) {
Class<?> cls = Ctors.MyInner.class;
int modifiers = cls.getModifiers();
System.out.println(modifiers); // prints 2
public class Ctors {
private class MyInner {
}
}
// $ javac Ctors.java && javap -c -private Ctors\$MyInner.class
// Compiled from "Ctors.java"
// class Ctors$MyInner {
// final Ctors this$0;
//