Skip to content

Instantly share code, notes, and snippets.

@jafow
jafow / multi-events.html
Created August 16, 2016 02:28
add multiple event listeners example
<!DOCTYPE html>
<head>
<title>adding multiple event listeners</title>
<style>
.square {
height: 200px;
width: 200px;
border: 2px solid green;
display: inline-block;
transition: width 1.5s, height 1.5s, background-color 1.5s, transform 1.5s
@jafow
jafow / get-elements-from-the-DOM.js
Created October 31, 2016 04:19
Framework - get elements on the DOM
// get elements by id:
document.getElementById('logout-button');
// returns single element
// => <button id='logout-button'>Logout!</button>
// get elements by class name:
document.getElementsByClassName('order-items');
// returns HTML collection of elements
@jafow
jafow / index.html
Created December 11, 2016 05:08
Dial
<div class="base">
<div class="completed"></div>
<div class="circle bg-blue">
<div class="circle fg-white">
<p class="percentage">50%</p>
</div>
</div>
</div>
@jafow
jafow / chrch.js
Created November 4, 2017 22:20
can't spell church without UR
const n = (fn, count) => count === 0 ? fn(count) : (fn(count), n(fn, count - 1))
const show = (x) => { console.log(`showing ${x}`) }
n(show, 4)
/**
* showing 4
* showing 3
* ...
<?php
$data = json_decode(file_get_contents('php://input'), TRUE);
$space_id = $data['id'];
$car_size = $data['size'];
$reg_space_count = array(
"type" => "reg",
"available" => 10
@jafow
jafow / game.php
Created February 1, 2018 08:09
21
<?php
class Game {
function __construct () {
$this->players = array();
}
/* deal 2 cards to each player in the game */
public function deal () {
foreach($this->players as $player_name => $player) {
$card_values = rand(2, 21);
@jafow
jafow / given.js
Created April 2, 2018 18:30
jsla - given
function given (_val) {
console.assert(typeof _val === 'number')
var val = _val
// look out it's the comma operator!
const multiply = (num) => (val *= num, methods)
const add = (num) => (val += num, methods)
const divide = (num) => (val /= num, methods)
@jafow
jafow / awl.md
Last active April 9, 2018 21:07
awl - spec

Overview

awl is a module for connecting peers that are both behind a p2p friendly NAT;

  • a rendezvous server Ṟ -- globally available IP addr -- listens for UDP connections

  • Ṟ connects two peers A → B;

    • If A wants to connect to B, A pings Ṟ and receives a response from Ṟ with B's IP/PORT info (B[IP]:B[PORT])
@jafow
jafow / vec_enum_example.rs
Created September 13, 2018 06:28
A Vec of Enums containing different types
fn main() {
// make a type Cell that contains a few different primitive types
enum Cell {
Text(String),
Num(i32),
Float(f32)
}
// make a list of them
let row = vec![
@jafow
jafow / main.rs
Created February 17, 2019 16:59
1s complement
fn main() {
// bitwise complement of unsigned int
let bw: u32 = 1;
let nbw = !bw;
assert_eq!(nbw, 4294967294);
// bitwise complement of signed int
let bw: i32 = 1;