Skip to content

Instantly share code, notes, and snippets.

@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 / 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);
<?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 / 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
* ...
@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 / 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 / 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 / client.js
Created August 15, 2016 04:03
client
require('lookup-multicast-dns/global')
const net = require('net')
const jsonStream = require('duplex-json-stream')
const host = process.argv[3]
const nick = process.argv[2] || 'guest'
var socket = net.connect(9494, `${host}.local`)
socket = jsonStream(socket)
@jafow
jafow / rec.js
Created August 13, 2016 22:59
turtles all teh way down
function rockPaperScissors(num) {
var res = []
var t = ['rock', 'paper', 'scissors']
if (num < 1) return []
function rps (part, n) {
part = part || []
if (part.length === n) return res.push(part)
for (let i = 0, len = t.length; i < len; i++) {
@jafow
jafow / mergeRanges.js
Created August 12, 2016 23:20
merge ranges
/**
* Write a function mergeRanges that takes an array of meeting time ranges and#
*
* Example:
* var times = [[0, 1], [3, 5], [4, 8], [10, 12], [9, 10]
*
* mergeRanges(times); -> [[0, 1], [3, 8], [9, 12]]
*
* Do not assume the ranges are in order
*/