Skip to content

Instantly share code, notes, and snippets.

@L8D
L8D / gist:5498414
Last active Dec 16, 2015
Snippet of a javascript date formatter.
View gist:5498414
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 Aug 4, 2013
Public SSH key
View gist:6148641
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSB6JUsqH814A5N78yQv/vy2UvHDUQGSIkknGiwRyQjX5h4aodgM6unvcIo1kZUldDCa4kxoUP1hN2Slb9UNWH/gwvSwmHI5T6M8W6b2kEcv4PX5BBn+V2aNI5KULq3OOevIrv5ofYf0shqRmX39mxLd2UU5tVLGYrx9OdYFK+2aRU6PJfMU8g2z6ArEqIvur81TeFnqdCMcihkM/1SnmBn/7c+/TfvjNm6xBBk2MC5Pw6iSTGi/JkIllMCXfV8FFvs4hYl0vfUowbBFdp5VQNrbYIJ8Qnn09hAilyFTRTlidkgAiAjr78pkClsisUA/M9lSjeD6G/7yhfO8o+Xv9J seed@Alex
@L8D
L8D / median.rb
Last active Feb 21, 2018
Median of array in ruby
View median.rb
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
View gist:6236756
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 Dec 29, 2015
Awesome port joiner helper thingy, @myndzi contributed the structure and stuff
View gist:7725276
/**
* 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 Dec 31, 2015
Mini and incomplete RL interpreter in Haskell
View gist:8007803
{-# 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 Jan 1, 2016
DiffBot article API for Node
View diffbot.js
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 Jan 3, 2016
Brainf*ck compiler using C as a midpoint.
View compile.js
#!/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 Jan 3, 2016
Brainf*ck-to-C compiler
View compile.hs
{-# 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 Jan 3, 2016
BFA Assembler in Haskell
View bfasm.hs
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
You can’t perform that action at this time.