Skip to content

Instantly share code, notes, and snippets.

View schell's full-sized avatar
🥑
mmm

Schell Carl Scivally schell

🥑
mmm
View GitHub Profile
@schell
schell / 8in7.js
Created March 23, 2012 00:23
How to store 8 7bit ascii characters in 7 8bit slots... (expanded)
var inputData = [];
var input = 'hi ther';
// Here we will store 8 7bit characters in 7 8bit slots...
inputData[0] = input.charCodeAt(0) & ((1 << 7) - 1);
inputData[0] = inputData[0] << 1 | input.charCodeAt(1) >> 6;
inputData[1] = input.charCodeAt(1) & ((1 << 6) - 1);
inputData[1] = inputData[1] << 2 | input.charCodeAt(2) >> 5;
@schell
schell / Curry.js
Last active December 16, 2015 00:59
Function currying using javascript.
function curry(f, arg) {
// Return a new curried function. Mmmm, spicy.
return function curriedFunction() {
// Take the other arguments and join them with our
// curried arg.
var args = Array.prototype.slice.call(arguments);
args.unshift(arg);
// Apply the function.
return f.apply(null, args);
};
@schell
schell / Compose.js
Last active December 16, 2015 00:59
Function composition in javascript.
function compose(g, f) {
// Return our composure.
return function composedFuction() {
var args = Array.prototype.slice.call(arguments);
return f.call(null, g.apply(null, args));
};
}
@schell
schell / gist:5461557
Last active December 16, 2015 16:10
learning ruby vtable opening up array
puts 'VTable format'
class Array
def print_vtable(cols)
rows = (self.length.to_f / cols).ceil
self.map { |index|
x = index % cols
y = index / cols
x * rows + y
@schell
schell / reinversion.1.hs
Last active December 18, 2015 13:49
Re-inversion of control. Part 1.
module Main where
import Graphics.UI.GLFW
import Control.Monad.Cont
import System.Exit ( exitSuccess )
main :: IO ()
main = do
putStrLn "Running glfw-cont-test."
module Main where
import Graphics.UI.GLFW
import Control.Monad.Cont
import System.Exit ( exitSuccess )
main :: IO ()
main = do
putStrLn "Running glfw-cont-test."
@schell
schell / reinversion.2.hs
Created June 18, 2013 07:03
reinversion of control, part 2
module Main where
import Graphics.UI.GLFW
import Control.Monad.Cont
import System.Exit ( exitSuccess )
main :: IO ()
main = do
putStrLn "Running glfw-cont-test."
@schell
schell / reinversion.3.hs
Created June 18, 2013 20:03
reinversion of control, part 3 - down the rabbit hole
module Main where
import Graphics.UI.GLFW
import Control.Monad.Cont
import System.Exit ( exitSuccess )
data GameState = GameState { keys :: [Key]
, wSize:: (Int, Int)
, mPos :: (Int, Int)
@schell
schell / readerSeq.hs
Last active December 19, 2015 00:59
Using Reader to sequence a thing over a list functions to produce a list of things.
toTriangleRect :: Rectangle -> [GLfloat]
toTriangleRect (Rectangle (x,y) (w,h)) = concat [tl, bl, br, br, tl, tr]
where tl = [x,y]
tr = [x+w,y]
bl = [x,y+h]
br = [x+w,y+h]
@schell
schell / Matrix.hs
Last active December 19, 2015 13:29
Matrix ops
module Geometry.Matrix where
import Data.List ( intercalate )
import Data.Maybe ( fromJust, fromMaybe )
import qualified Data.List as L
{- The Matrix -}
type Matrix a = [Vector a]