This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{ | |
collections::{HashMap, HashSet}, | |
fmt, | |
fmt::{Display, Formatter}, | |
hash::Hash, | |
iter::FromIterator, | |
sync::OnceLock, | |
}; | |
#[derive(Debug, Hash, Clone, Copy, Eq, PartialEq)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* AStarfinding | |
* | |
* local path_find = require "pathfinding" | |
* | |
* local function neighbors(add, x, y, dist) | |
* add(x+1, y, hint, 1) | |
* end | |
* | |
* local r = path_find(sx, sy, tx, ty, neighbors) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local assert = assert | |
local type = type | |
local getmetatable = getmetatable | |
local setmetatable = setmetatable | |
local xpcall = xpcall | |
local debug_traceback = debug.traceback | |
local Promise = {} do | |
local Fulfilled = "Fulfilled" | |
local Rejected = "Rejected" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define LUA_LIB | |
#include <lua.h> | |
#include <lauxlib.h> | |
#include <assert.h> | |
#include <string.h> | |
static size_t b58_posrelatI(lua_Integer pos, size_t len) { | |
if (pos > 0) | |
return (size_t)pos; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <lua.h> | |
#include <lauxlib.h> | |
#include <string.h> | |
#define BASE 58 | |
#define BYTE (1<<CHAR_BIT) | |
#define BASE58_ALPHABET "base58.Alphabet" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Helpers {{{1 | |
local function fail_on_missing_tbl(t, missing_name) | |
missing_name = missing_name or 'table entry' | |
return setmetatable(t, {__index = function(t, k) | |
error(('No %s with key "%s" (in %s).'):format(missing_name, k, t)) | |
end | |
}) | |
end | |
fail_on_missing_tbl(_G, 'global'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
io.input "../../Downloads/area_code_2018.csv" | |
io.output "area_code.py" | |
local map = {} | |
for l in io.lines() do | |
local code = l:match "^%d%d%d%d%d%d" | |
if tonumber(code) % 1000 > 0 and not map[code] then | |
map[#map+1] = code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
class List { | |
struct Node { | |
Node* next; | |
int val; | |
Node(int val, Node* next = nullptr) | |
: next(next), val(val) {} | |
}; | |
Node* head_; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# vim: ft=sh nu et sw=2 fdc=2 | |
select_one() { | |
local cmd; read -d '' cmd <<EOF | |
tell application "iTerm2" to activate | |
tell application "iTerm2" to set thefile to choose $1 | |
do shell script "echo " & (quoted form of POSIX path of thefile as Unicode text) | |
EOF | |
osascript -e "$cmd" 2>/dev/null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef _MSC_VER | |
# define _CRT_SECURE_NO_WARNINGS | |
# define _CRT_NONSTDC_NO_WARNINGS | |
#endif | |
#define LUA_LIB | |
#include <lua.h> | |
#include <lauxlib.h> | |
#if LUA_VERSION_NUM < 502 |
NewerOlder