Skip to content

Instantly share code, notes, and snippets.

View nicolasbrugneaux's full-sized avatar
🤓
Nerdin'

Nicolas Brugneaux nicolasbrugneaux

🤓
Nerdin'
View GitHub Profile
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)
}
@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",
-- 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 / 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 )
{
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 / 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)
-- zcat 2015/07/0723*trace* |
-- grep -o "__id.*duration_..__" |
-- sed 's/__*\|id\|duration/ /g' |
-- sed 's/^ *\| *$//g' |
-- sed 's/ */ /' |
-- nawk '{
-- max[$1] = !($1 in max) ? $2 : ($2 > max[$1]) ? $2 : max[$1]
-- } END {
-- for (i in max)
-- print i, max[i]
@nicolasbrugneaux
nicolasbrugneaux / migration.js
Created August 21, 2015 10:03
spotify: migrate to rdio.
// go to the proper iframe in the console, should be something like:
// 'collection-app-spotify'...
// run that
[].map.call(document.querySelectorAll( 'div.list-group>.list-group-item-media.playable'), function(list){
return list.getAttribute('data-uri')
} );
// copy all these links in http://resp.in/
@nicolasbrugneaux
nicolasbrugneaux / fuzzy.js
Last active September 21, 2015 14:41
fuzzy-string-matching-using-cosine-similarity
// http://blog.nishtahir.com/2015/09/19/fuzzy-string-matching-using-cosine-similarity/
'use strict';
Set.intersection = function*( set1, set2 )
{
for ( let value of set1.values() )
{
if ( set2.has( value ) )
{
@nicolasbrugneaux
nicolasbrugneaux / drag.js
Created September 25, 2015 14:44
Make a div draggable – movable.
const getNumberFromCss = ( rules, cssName ) => parseInt( rules[cssName], 10 );
export const makeDraggable = ( element ) =>
{
const initial =
{
x : null,
y : null,
top : null,
right : null