Skip to content

Instantly share code, notes, and snippets.

View nicolasbrugneaux's full-sized avatar
🤓
Nerdin'

Nicolas Brugneaux nicolasbrugneaux

🤓
Nerdin'
View GitHub Profile
@nicolasbrugneaux
nicolasbrugneaux / navigate.hs
Created July 21, 2015 12:28
more haslly please?
navigate :: Direction -> Coordinate -> Maze -> Maybe Coordinate
navigate direction (x, y) m = case direction of
N -> if isJust (getCellAt newCell m) then Just newCell else Nothing where
newCell = (x - 1, y)
E -> if isJust (getCellAt newCell m) then Just newCell else Nothing where
newCell = (x, y + 1)
S -> if isJust (getCellAt newCell m) then Just newCell else Nothing where
newCell = (x + 1, y)
W -> if isJust (getCellAt newCell m) then Just newCell else Nothing where
newCell = (x, y - 1)
export default class Collection
{
constructor( { collection=[], shouldUpdateBeforeRender=false, shouldUpdateAfterRender=false } )
{
this._collection = collection;
this._shouldUpdateBeforeRender = shouldUpdateBeforeRender;
this._shouldUpdateAfterRender = shouldUpdateAfterRender;
}
// blah blah custom methods
}
@nicolasbrugneaux
nicolasbrugneaux / search.js
Last active August 29, 2015 14:22
words comparison
import { levenshtein, fuzzyMatch } from './utils.js';
import Words from './database-all-words';
const search = function( event )
{
const query = event.target.value.toLowerCase().trim();
const words = Words.getAll();
if ( query )
{
-- problem 31
primes :: [Int]
primes = nextPrime [2..]
where nextPrime (p:xs) = p:nextPrime [x | x <- xs, x `mod` p > 0]
-- problem 35
primeFactors :: Int -> [Int]
primeFactors n = [ x | x <- (takeWhile (< n) primes), n `mod` x == 0 ]
@nicolasbrugneaux
nicolasbrugneaux / gist:c3622f320d658729c1da
Created February 12, 2015 18:13
swift experimentations
let fieldAliases: [String: String] =
[
"SCMActionConfirmed" : "confirmed",
"SCMAmount" : "amount",
"SCMBrand" : "brand",
"SCMCategory" : "category",
"SCMCurrency" : "currency",
"SCMDescription" : "description",
"SCMProductID" : "identifier",
"SCMProductImageURL" : "photo",
use std::io::net;
use std::io::net::ip::{Port, SocketAddr};
use std::io::TcpStream;
use std::kinds::marker::NoCopy;
enum Client {
Connected(ConnectedClient),
Disconnected(DisconnectedClient)
}