Skip to content

Instantly share code, notes, and snippets.

View L8D's full-sized avatar

Tenor L8D

View GitHub Profile
@L8D
L8D / gist:6236756
Last active December 21, 2015 02:39
def longest_string array
array.sort_by! &:length
max_length = array.last.length
array.reject { |x| x.length < max_length }
end
@L8D
L8D / gist:7725276
Last active December 29, 2015 20:39
Awesome port joiner helper thingy, @myndzi contributed the structure and stuff
/**
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
@L8D
L8D / gist:8007803
Last active December 31, 2015 15:38
Mini and incomplete RL interpreter in Haskell
{-# LANGUAGE LambdaCase #-}
import Control.Monad ((>=>))
import Data.Maybe (listToMaybe, fromMaybe)
import Data.Char (toLower)
import Data.List (intercalate)
type Item = Int
type Stack = [Item]
@L8D
L8D / diffbot.js
Last active January 1, 2016 23:19
DiffBot article API for Node
var querystring = require('querystring'),
util = require('util'),
request = require('request');
var ARTICLE_URL = 'http://api.diffbot.com/v2/article';
exports.article = function(url, token, cb, options) {
options = options || {};
if (!url || !token || !cb) throw TypeError('3 arguments required.');
@L8D
L8D / compile.js
Last active January 3, 2016 03:18
Brainf*ck compiler using C as a midpoint.
#!/usr/bin/env node
var fs = require('fs'),
spawn = require('child_process').spawn,
argv = require('optimist').argv;
var gcc = spawn('gcc', [
'--std=c99',
'-o', argv.o || argv._[0] ? argv._[0].split('.')[0] : 'a.out',
'-x', 'c',
'-'
@L8D
L8D / compile.hs
Last active January 3, 2016 10:29
Brainf*ck-to-C compiler
{-# LANGUAGE OverloadedStrings #-}
codeChar :: Char -> String
codeChar c = case c of
'+' -> "++*p;"
'-' -> "--*p;"
'>' -> "++p;"
'<' -> "--p;"
'.' -> "fputc(*p, mode ? f : stdout);"
'|' -> "fflush(mode ? f : stdout);"
@L8D
L8D / bfasm.hs
Last active January 3, 2016 13:19
BFA Assembler in Haskell
import Data.Char (isSpace)
import Data.Maybe (listToMaybe, fromMaybe)
maybeRead :: Read a => String -> Maybe a
maybeRead = fmap fst . listToMaybe . reads
parseLine :: String -> (Int, String)
parseLine = uncurry ((,) . fromMaybe 1 . maybeRead) . break isSpace
makeLine :: (Int, String) -> String
@L8D
L8D / bf.sh
Last active January 3, 2016 13:19
Script to compose optimize.hs, compile.hs and GCC.
#!/usr/bin/env bash
cat $1 | ./compile | gcc --std=c99 -x c -o $2 -
@L8D
L8D / hi.bf
Last active January 3, 2016 13:19
Output: "hi\n"
+++++ +++++ [ > +++++ +++++ > + << - ] > ++++ . + . > .
@L8D
L8D / test.js
Last active January 4, 2016 00:19 — forked from oroce/test.js
var gimmeFullscreenMethod = function() {
'use strict';
var el = document.documentElement, open, cancel, video;
open = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen;
cancel = el.exitFullscreen || el.webkitExitFullscreen || el.mozExitFullscreen || el.msExitFullscreen;
if (open) {
return {