Skip to content

Instantly share code, notes, and snippets.

View L8D's full-sized avatar

Tenor L8D

View GitHub Profile
@L8D
L8D / gist:5498414
Last active December 16, 2015 21:19
Snippet of a javascript date formatter.
return d.getUTCFullYear()
+ '-' + zeroFill(d.getUTCMonth() + 1, 2)
+ '-' + zeroFill(d.getUTCDate(), 2)
+ 'T' + zeroFill(d.getUTCHours(), 2)
+ ':' + zeroFill(d.getUTCMinutes(), 2)
+ ':' + zeroFill(d.getUTCSeconds(), 2)
+ '.' + zeroFill(d.getUTCMilliseconds() * 1000, 6)
+ 'Z';
@L8D
L8D / gist:6148641
Created August 4, 2013 01:14
Public SSH key
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSB6JUsqH814A5N78yQv/vy2UvHDUQGSIkknGiwRyQjX5h4aodgM6unvcIo1kZUldDCa4kxoUP1hN2Slb9UNWH/gwvSwmHI5T6M8W6b2kEcv4PX5BBn+V2aNI5KULq3OOevIrv5ofYf0shqRmX39mxLd2UU5tVLGYrx9OdYFK+2aRU6PJfMU8g2z6ArEqIvur81TeFnqdCMcihkM/1SnmBn/7c+/TfvjNm6xBBk2MC5Pw6iSTGi/JkIllMCXfV8FFvs4hYl0vfUowbBFdp5VQNrbYIJ8Qnn09hAilyFTRTlidkgAiAjr78pkClsisUA/M9lSjeD6G/7yhfO8o+Xv9J seed@Alex
@L8D
L8D / median.rb
Last active February 21, 2018 21:41
Median of array in ruby
def median_of a
return nil if a.empty?
sorted = a.sort
len = sorted.length
(sorted[(len - 1) / 2] + sorted[len / 2]) / 2.0
end
@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