Skip to content

Instantly share code, notes, and snippets.

@bsitruk
bsitruk / combining-map-with-concatAll.js
Last active November 20, 2015 11:38
Functional programming: Combining map with concatAll
function() {
var movieLists = [
{
name: "New Releases",
videos: [
{
"id": 70111470,
"title": "Die Hard",
"boxart": "http://cdn-0.nflximg.com/images/2891/DieHard.jpg",
"uri": "http://api.netflix.com/catalog/titles/movies/70111470",
@bsitruk
bsitruk / combine-map-with-reduce.js
Last active November 20, 2015 11:37
Functional programming: Combining map with reduce
function() {
var movieLists = [
{
name: "New Releases",
videos: [
{
"id": 70111470,
"title": "Die Hard",
"boxarts": [
{ width: 150, height:200, url:"http://cdn-0.nflximg.com/images/2891/DieHard150.jpg" },
@bsitruk
bsitruk / combine-map-with-zip.js
Last active November 20, 2015 14:18
Functional programming: Combine map with zip
function() {
var movieLists = [
{
name: "New Releases",
videos: [
{
"id": 70111470,
"title": "Die Hard",
"boxarts": [
{ width: 150, height:200, url:"http://cdn-0.nflximg.com/images/2891/DieHard150.jpg" },
@bsitruk
bsitruk / join-array-by-key.js
Created November 20, 2015 14:15
Functional programming: join two arrays by a key
function() {
var lists = [
{
"id": 5434364,
"name": "New Releases"
},
{
"id": 65456475,
name: "Thrillers"
}
@bsitruk
bsitruk / 0_reuse_code.js
Created November 20, 2015 14:18
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@bsitruk
bsitruk / date-tips.js
Last active November 20, 2015 15:56
Date manipulation
var tenDaysAgo = new Date( now.getFullYear(), now.getMonth(), now.getDate() - 10); // Negative date works !!
var negativeDate = new Date(2015, 10, -1); // 30 Octobre 2015
var elappsedTime = Date.now() - tenDaysAgo; // Soustraire deux dates utilisent automatiquement les timeStamps
@bsitruk
bsitruk / animations.css
Created February 26, 2016 12:50
SVG2CSS : output files
@keyframes dropball {
0% {
bottom: 200px;
}
2% {
bottom: 198.89046144485474px;
}
4% {
bottom: 197.5577425956726px;
}
@bsitruk
bsitruk / string2Number
Created February 22, 2017 21:10
Fastest way to convert a string to a number
var numberOne = +'1'; // 1
@bsitruk
bsitruk / reset_tables.plpgsql
Created July 5, 2017 13:57
PostgreSQL function: Remove all data from the db's tables, and restart id sequences.
DECLARE
statements CURSOR FOR
SELECT tablename FROM pg_tables
WHERE schemaname = 'public';
BEGIN
FOR stmt IN statements LOOP
EXECUTE 'TRUNCATE TABLE ' || quote_ident(stmt.tablename) || ' CASCADE;';
EXECUTE 'ALTER SEQUENCE ' || quote_ident('' || stmt.tablename || '_id_seq') || ' RESTART WITH 1';
END LOOP;
END;
@bsitruk
bsitruk / functional.py
Last active July 30, 2019 08:20
Some functional utilities in python.
from tempfile import NamedTemporaryFile, TemporaryDirectory
def compose(g, f):
"""Right to left function composition."""
return lambda *args, **kwargs: g(f(*args, **kwargs))
def temporarify(action, directory=False):
"""