Skip to content

Instantly share code, notes, and snippets.

View jacksarick's full-sized avatar
⛑️
Vibing

Jack Sarick jacksarick

⛑️
Vibing
View GitHub Profile
type # First we must describe the words we use
Name = distinct string # Names are special words
Node = ref object # Nodes simply reference ...
nodes: seq[Node] # ... other nodes.
name: Name # They can be distinguished by their Name
proc `<->`(a: var Node, b: Node) {.inline.} =
a.nodes = a.nodes & b
b.nodes = b.nodes & a
@jacksarick
jacksarick / unholy.html
Created March 14, 2018 19:04
An unholy image generator
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Unholy Image Generator</title>
</head>
<body>
<img id="base_image" style="display: none;">
<img id="ghost_image" style="display: none;">
<canvas id="canvas" width="800" height="800" style="border:1px solid black;"></canvas>
@jacksarick
jacksarick / d_and_d_gambling.py
Created January 3, 2018 23:14
Allows for stats on dice rolls. Can be expanded to more complicated patterns
# Gambling Checker
from random import randint
roll = lambda x, y: [randint(1, y) for _ in range(x)]
wins = lambda a, b: sum(map(lambda x: x[0] > x[1], zip(a,b)))
rate = lambda a, b, s: "A d" + str(a) + " beats a d" + str(b) + " about " + str((wins(roll(s, a), roll(s,b))/float(s))*100) + " of the time"
print(rate(20, 12, 1000000))
print(rate(20, 10, 1000000))
print(rate(20, 8, 1000000))
@jacksarick
jacksarick / land_of_nim.nim
Created April 21, 2017 04:51
A little game I'm making in Nim
import strutils as str
## Game "rules"
# The types in this game
type
# Types for the player
Pos = tuple[x: int, y: int]
Stats = tuple[hp: int, ap: int]
Class = tuple[name: string, atk: int, def: int, mov: int, mag: int]
Player = tuple[pos: Pos, stat: Stats, class: Class]
@jacksarick
jacksarick / nginx_macro.tcl
Last active September 5, 2020 09:17
A little script to build custom nginx config file macros
#!/usr/bin/tclsh
# Open & read file
set a [open $argv]
set lines [split [read $a] "\n"]
close $a;
# Loop through lines
foreach line $lines {
@jacksarick
jacksarick / main.lua
Created February 13, 2017 05:41
Orthographic projections for my math IA
GRID_X = 20
GRID_Y = 20
CELL = 30
FOCAL = 2
points = {{5, 5, 5}, {5, 5, -5}, {5, -5, 5}, {5, -5, -5}, {-5, 5, 5}, {-5, 5, -5}, {-5, -5, 5}, {-5, -5, -5}}
function ortho_transform(p)
x, y, z = unpack(p)
@jacksarick
jacksarick / wandering-turtles.nlogo
Last active December 16, 2016 04:46
My first NetLogo program about turtles wandering lloking for food
@jacksarick
jacksarick / http-server.js
Created November 13, 2016 02:08
Simple http server in standard node
var http = require('http');
const PORT = 8080;
function handler(request, response){
response.end('Requested path: ' + request.url);
}
var server = http.createServer(handler);
server.listen(PORT, function(){
@jacksarick
jacksarick / jackQuery.js
Last active November 13, 2016 16:01
A small home-grown version of jQuery
/* A small home-grown version of jQuery from https://gist.github.com/jacksarick/960528f69edf3cb9262183c26130b8f6*/
function Tag(x) {
if (x[0] == "#") {
this.$ = document.getElementById(x.slice(1));
}
if (x[0] == ".") {
this.$ = document.getElementsByClassName(x.slice(1))[0];
}
this.style = function(a, v) { this.$.style[a] = v; }
@jacksarick
jacksarick / style.css
Last active October 12, 2016 03:28
The worlds most basic CSS stylesheet that looks half decent, courtesy http://jgthms.com/web-design-in-4-minutes/#header
/* Basic CSS stylesheet from https://gist.github.com/jacksarick/9fab0439a0b5a043cf461f616195cd84 */
body {
margin: 0 auto;
max-width: 50em;
line-height: 1.5;
padding: 4em 1em;
color: #555;
font-family: "Helvetica", "Arial", sans-serif;
margin-top: 1em;