Skip to content

Instantly share code, notes, and snippets.

View jsanders's full-sized avatar

James Sanders jsanders

View GitHub Profile
@jsanders
jsanders / PointDist.java
Last active March 28, 2019 04:11
Java data class / record
public class PointDist {
public static void main(String[] args) {
var point = new Point(3, 4);
System.out.println(String.format("x: %d - y: %d - distance: %f", point.x(), point.y(), point.dist()));
}
static record Point(int x, int y) {
double dist() {
return Math.sqrt(x * x + y * y);
}
@jsanders
jsanders / failures.log
Last active January 25, 2016 08:00
Servo WebSocket test failures
▶ TIMEOUT [expected OK] /websockets/Create-Secure-extensions-empty.htm
▶ Unexpected subtest result in /websockets/Create-Secure-extensions-empty.htm:
└ NOTRUN [expected PASS] W3C WebSocket API - Create Secure WebSocket - wsocket.extensions should be set to '' after connection is established - Connection should be closed
▶ Unexpected subtest result in /websockets/Create-Secure-extensions-empty.htm:
│ FAIL [expected PASS] W3C WebSocket API - Create Secure WebSocket - wsocket.extensions should be set to '' after connection is established - Connection should be opened
│ → assert_equals: extensions should be empty expected (string) "" but got (undefined) undefined
│ @http://web-platform.test:8000/websockets/Create-Secure-extensions-empty.htm:9:13
@jsanders
jsanders / tickertape.log
Created December 18, 2015 05:15
Websockets in Stockastic
iex(5)> import Stockastic.Tickertape, only: [connect!: 2, loop!: 2]
nil
iex(6)> connect!("KAH40660714", "TYHBEX") |> loop!(fn(text) -> IO.puts(text) end)
{"ok":true,"quote":{"symbol":"PMI","venue":"TYHBEX","bid":7947,"bidSize":57,"askSize":0,"bidDepth":26743,"askDepth":0,"last":7617,"lastSize":92,"lastTrade":"2015-12-18T05:14:05.115858945Z","quoteTime":"2015-12-18T05:14:10.030310726Z"}}
{"ok":true,"quote":{"symbol":"PMI","venue":"TYHBEX","bid":7947,"bidSize":57,"askSize":0,"bidDepth":13400,"askDepth":0,"last":7617,"lastSize":92,"lastTrade":"2015-12-18T05:14:05.115858945Z","quoteTime":"2015-12-18T05:14:10.03139461Z"}}
{"ok":true,"quote":{"symbol":"PMI","venue":"TYHBEX","bid":7947,"bidSize":57,"askSize":0,"bidDepth":57,"askDepth":0,"last":7617,"lastSize":92,"lastTrade":"2015-12-18T05:14:05.115858945Z","quoteTime":"2015-12-18T05:14:10.032434757Z"}}
...
@jsanders
jsanders / out.log
Created December 2, 2015 06:04
output using --log-mach tmp/log.txt --log-mach-level debug
 0:00.91(B LOG: MainThread INFO(B Using 8 client processes
 0:00.94(B LOG: MainThread INFO(B Generating new CA in /var/folders/py/jqgj6kjs5fl3pcjnk916ljrr0000gp/T/tmpPYhIJE
 0:00.99(B PROCESS_OUTPUT: MainThread (pid:89918) Full command: /usr/local/bin/openssl req -config /var/folders/py/jqgj6kjs5fl3pcjnk916ljrr0000gp/T/tmpPYhIJE/openssl.cfg -batch -new -newkey rsa:2048 -keyout /var/folders/py/jqgj6kjs5fl3pcjnk916ljrr0000gp/T/tmpPYhIJE/cakey.pem -out /var/folders/py/jqgj6kjs5fl3pcjnk916ljrr0000gp/T/tmpPYhIJE/careq.pem -subj /CN=web-platform-tests -passout pass:web-platform-tests
(pid:89918) "Generating a 2048 bit RSA private key
..............+++
........+++
writing new private key to '/var/folders/py/jqgj6kjs5fl3pcjnk916ljrr0000gp/T/tmpPYhIJE/cakey.pem'
-----
"
 0:01.01(B PROCESS_OUTPUT: MainThread (pid:89919) Full command: /usr/local/bin/openssl ca -config /var/folders/py/jqgj6kjs5fl3pcjnk916ljrr0000gp/T/tmpPYhIJE/openssl.cfg -batch -create_serial -keyfil
@jsanders
jsanders / gist:c7949126f041c6df725f
Created December 2, 2015 05:58
test-wpt with RUST_LOG
$ RUST_LOG=debug ./mach test-wpt tests/wpt/web-platform-tests/websockets/interfaces/WebSocket/events/018.html
Running 1 tests in web-platform-tests
Ran 1 tests finished in 24.0 seconds.ket/events/018.html
• 1 ran as expected. 0 tests skipped.
@jsanders
jsanders / gulpfile.babel.js
Created October 27, 2015 02:15
Gulp + ES 2015 / Babel + PostCSS + Lost + BrowserSync
import gulp from 'gulp';
import postcss from 'gulp-postcss';
import sourcemaps from 'gulp-sourcemaps';
import cssnano from 'cssnano';
import autoprefixer from 'autoprefixer';
import lost from 'lost';
import {create as bsCreate} from 'browser-sync';
const browserSync = bsCreate();
const dirs = {
@jsanders
jsanders / compose.py
Last active August 29, 2015 14:26
Demonstrate how compose could be defined in python
def compose(*funcs):
return lambda x: reduce(lambda acc, f: f(acc), funcs[::-1], x)
def double(x):
return x + x
def square(x):
return x * x
print(compose(double, square)(2)) #=> 8
@jsanders
jsanders / github-trello.md
Created April 10, 2015 22:27
github vs. trello

Github

Pros

  • Pull requests are the thing for getting dev done, seeing what others have done, and discussing it. I love pull requests.

Cons

  • Developer-centric workflow that doesn't provide much value to the rest of the business, because it has no interest in that at all.
  • Not particularly flexible organization of anything, milestones are a bit clunky to use, so it's mostly just labels.

Neutral

  • Individual issues are a pretty good place for discussion, but not a killer feature at all like PRs.
@jsanders
jsanders / min_by.rb
Created April 4, 2015 21:22
Functional min_by
def min_by(ary, fn)
first, *rest = ary;
min_elem, _ = rest.reduce([first, fn.call(first)]) do |(min_elem, min), new_elem|
if (new_min = f.call(new_elem)) < min
[ new_elem, new_min ]
else
[ min_elem, min ]
end
end
min_elem
@jsanders
jsanders / quarter.lua
Created July 9, 2014 18:16
Hydra bindings for screen quarters
-- Returns a function that can be used to move into quarter grid
function quarter(horiz, vert)
local win = window.focusedwindow()
local newframe = win:screen():frame_without_dock_or_menu()
local halfw = newframe.w / 2
local halfh = newframe.h / 2
newframe.h = horiz == "full" and newframe.h or halfh
newframe.w = vert == "full" and newframe.w or halfw
newframe.y = horiz == "bottom" and halfh or newframe.y