Skip to content

Instantly share code, notes, and snippets.

View sebabouche's full-sized avatar

Sébastien Nicolaïdis sebabouche

  • Sifnos.io
  • La Trinité sur Mer
View GitHub Profile
@sebabouche
sebabouche / ramda3.js
Created June 22, 2018 20:17
ramda: cond, always, T, identity
import { cond, always, lte, gte, T, __, identity } from "ramda"
const water = cond([
[lte(__, 0), temp => `water freezes at ${temp}°C`],
[gte(__, 100), temp => `water boils at ${temp}°C`],
[T, temp => `nothing special happens at ${temp}°C`],
])
console.log(water(-222))
@sebabouche
sebabouche / ramda2.js
Created June 22, 2018 20:16
ramda: ifElse, gte, lt, always, identity, whn, unless
import { ifElse, gte, lt, __, always, identity, when, unless } from "ramda"
// const forever21 = age => (age >= 21 ? 21 : age)
// const forever21 = ifElse(gte(__, 21), always(21), identity)
// const forever21 = unless(lt(__, 21), always(21))
const forever21 = when(gte(__, 21), always(21))
console.log("forever21(24)", forever21(24))
console.log("forever21(16)", forever21(16))
@sebabouche
sebabouche / ramda1.js
Created June 22, 2018 20:16
ramda: map, filter, partial, partialRight, curry, __, pipe
import { map, filter, partial, partialRight, curry, __, pipe } from "ramda"
const publishedInYear = curry((year, book) => book.year === year)
const titlesForYear = curry((year, books) =>
pipe(
filter(publishedInYear(year)),
map(book => book.title),
)(books),
)
@sebabouche
sebabouche / ramda0.js
Created June 22, 2018 20:15
ramda: compose, bboth, either, gte, prop, equals, __
import { compose, both, either, gte, prop, equals, __ } from "ramda"
const OUR_COUNTRY = "France"
const wasBornInCountry = compose(
equals(OUR_COUNTRY),
prop("birthCountry"),
)
const wasNaturalized = compose(
Boolean,
@sebabouche
sebabouche / setTimeoutWithAsyncAwait
Created January 31, 2018 22:30
Using setTimeout with async/await
let wait = ms => new Promise(resolve => setTimeout(resolve, ms))
let foo = async () => {
await wait(2000)
await this._doSomething()
}
@sebabouche
sebabouche / awsUploader.js
Created January 31, 2018 21:12
aws and filepreviews.io
import aws from "aws-sdk"
import shortid from "shortid"
import FilePreviews from "filepreviews"
import {
REACT_APP_S3_ACCESS_KEY_ID,
REACT_APP_S3_SECRET_KEY,
REACT_APP_S3_REGION,
REACT_APP_S3_BUCKET_NAME,
REACT_APP_FILEPREVIEWS_API_KEY,
@sebabouche
sebabouche / pipeline-reduce-example.js
Created January 28, 2018 16:35
A pipeline of transformations example using reduce
const increment = input => input + 1
const decrement = input => input - 1
const double = input => input * 2
const halve = input => input / 2
const initialValue = 10
const pipeline = [
increment,
double,
@sebabouche
sebabouche / Python: playing with getattr, setattr
Created November 29, 2017 23:34
These getattr and setattr can be very helpful!
class MyObject(object):
def __init__(self):
self.my_value = 0
my_obj = MyObject()
getattr(eval('my_obj'), 'my_value')
setattr(eval('my_obj'), 'my_value', 1)
@sebabouche
sebabouche / batch_update_process.py
Created November 14, 2017 22:00
Batch update a big query based on total and batch quantity
import math
# from b_estimates.models import BEstimate
#
# be_list = BEstimate.objects.all()
be_list = list(range(4934))
# total_count = be_list.count()
total_count = 4934
batch_count = 500
iterations = math.ceil(total_count / batch_count)
@sebabouche
sebabouche / Playing with map, filter & reduce in... Python3 -_-.py
Last active October 31, 2017 22:07
Exercises with map, filter, reduce without using list comprehension (which is not very pythonic but interesting).
TEMPERATURES = [37, 42, -24, 39]
def fahrenheit(T):
return ((float(9)/5)*T + 32)
def celsius(T):
return (float(5)/9)*(T-32)
print(list(map(fahrenheit, TEMPERATURES)))