Skip to content

Instantly share code, notes, and snippets.

View kdubbels's full-sized avatar
🔮
doing orb stuff

Kristofer Dubbels kdubbels

🔮
doing orb stuff
View GitHub Profile
@kdubbels
kdubbels / chessboard.js
Last active August 18, 2020 16:38
Write a program that creates a string that represents an 8×8 grid, using newline characters to separate lines. At each position of the grid there is either a space or a "#" character. The characters should form a chessboard.
// Write a program that creates a string that represents an 8×8 grid,
// using newline characters to separate lines.At each position of
// the grid there is either a space or a "#" character.The characters
// should form a chessboard.
// Passing this string to console.log should show something like this:
// # # # #
// # # # #
// # # # #
@kdubbels
kdubbels / countChar
Last active August 12, 2020 20:03
Solution to the "Bean Counting" exercise in Chapter 3 of "Eloquent JavaScript" by Marijn Haverbeke
// from https://eloquentjavascript.net/03_functions.html#i_3rsiDgC2do
/*
Write a function countBs that takes a string as its only argument
and returns a number that indicates how many uppercase “B” characters
there are in the string.
Next, write a function called countChar that behaves like countBs,
except it takes a second argument that indicates the character that
is to be counted (rather than counting only uppercase “B” characters).
@kdubbels
kdubbels / partial-recursive-functions.js
Created April 8, 2018 07:16
Partial recursive functions in JavaScript
const ZERO = () => 0
const increment = (n) => n + 1
// sanity check
const zero = ZERO() // 0
const one = increment(zero) // 1
const two = increment(increment(zero)) // 2
const three = increment(increment(increment(zero))) // 3
// this one gets a little hazy heh
@kdubbels
kdubbels / gist:95d24d7906cb36a275bdc120c7b93757
Last active April 20, 2018 19:15
lambda calculus in js
//from Michaelson (1989)
const identity = (x) => x;
const self_apply = (s) => s(s);
const apply = (func) => (arg) => func(arg);
const identity2 = (x) => (apply(identity))(x)
const self_apply2 = (s) => (apply(s))(s)
set nocompatible " be iMproved, required
filetype off " required
set t_Co=256
set number " Display line numbers beside buffer
set scrolloff=5 " Keep at least 5 lines below cursor
filetype plugin indent on
" show existing tab with 4 spaces width
set tabstop=4
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH=/Users/kdubbels/.oh-my-zsh
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="robbyrussell"
require 'sinatra'
get '/hi' do
"Hello World!"
end
@kdubbels
kdubbels / palindrome.io
Last active August 28, 2017 07:59
Palindrome Detection in Io
palindrome := method(a, a reverse == a)
palindrome("racecar") // ==> true
palindrome("foobar") // ==> false
@kdubbels
kdubbels / collatz.js
Created August 17, 2017 00:07
Collatz conjecture in ES6
const collatz = (n) => {
if (n == 1) {
console.log(n);
return 1;
}
if (n % 2 == 0) { // n is even
console.log(n);
return 1 + collatz(n/2)
} else { // n is odd
@kdubbels
kdubbels / ackermann.js
Created August 17, 2017 00:07
Ackermann function in ES6
const ackermann = (m, n) => {
if (m === 0) {
return n+1
}
if (n === 0) {
return ackermann((m - 1), 1);
}
if (m !== 0 && n !== 0) {