Skip to content

Instantly share code, notes, and snippets.

View day6.rs
// https://adventofcode.com/2019/day/6
// https://doc.rust-lang.org/beta/std/collections/struct.HashMap.html
use std::fs;
use std::collections::{
HashSet, HashMap, VecDeque
};
fn main() {
let mut graph = HashMap::new();
let mut reachable = HashMap::new();
View vis-sprintf.patch
index 124e380..1e8b8f8 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -2643,7 +2643,8 @@ void vis_lua_init(Vis *vis) {
* - /usr/(local/)?share/vis (or whatever is specified during ./configure)
* - package.path (standard lua search path)
*/
- char path[PATH_MAX];
+ char *path;
+ size_t path_len;
View 15-2.lisp
(defun next (prev factor)
(rem (* prev factor) 2147483647))
(defun solve/2 (limit initial-a initial-b)
(let ((gen-a initial-a)
(gen-b initial-b)
(match-count 0)
(success-count 0))
(tagbody
next-a
View prettier-vis.lua
m = {}
m.prettier_command = "npx prettier"
m.prettier_args = " "
function format_prettier()
local file = vis.win.file
local cmd = m.prettier_command .. m.prettier_args .. file.path
-- Range should default to selection if present:
View scratch.st
| win toolbar workspc workspcModel loadBtn saveBtn |
win _ SystemWindow new.
workspcModel _ Workspace withText: 'Transcript show: ''foo'''.
workspc _ TextModelMorph withModel: workspcModel.
toolbar _ LayoutMorph newRow.
loadBtn _ PluggableButtonMorph model: workspc
action: #switch
View clx-xinerama-test.lisp
;; (ql:quickload :clx)
(destructuring-bind (hostname display-id screen-id protocol)
(xlib::get-default-display ":1")
(let ((display (xlib:open-display hostname :display display-id :protocol protocol)))
(xlib/xinerama:xinerama-is-active display)))
View sortNumbers.js
// time sortNumbers.js => 0.196
function randomInteger(lowerBound, upperBound) {
return lowerBound + Math.floor(Math.random() * (upperBound - lowerBound));
}
function* randomNumbers(count) {
for (var i=0; i < count; i++) {
yield randomInteger(1, 10);
}
}
View sortNumbers.js
// time sortNumbers.js => 0.196
function randomInteger(lowerBound, upperBound) {
return lowerBound + Math.floor(Math.random() * (upperBound - lowerBound));
}
function* randomNumbers(count) {
for (var i=0; i < count; i++) {
yield randomInteger(1, 10);
}
}
View foo.py
def parse_year_month(year_month):
return year_month.split("-")
def find_teams_that_disappeared_in_month(year_month):
current_year, current_month = parse_year_month(year_month)
if current_month == "01": # O is_january(current_month)
return frozenset()
previous_month = month_before(current_month)
current_teams = teams_in_month(current_month)