This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let wait = ms => new Promise(resolve => setTimeout(resolve, ms)) | |
let foo = async () => { | |
await wait(2000) | |
await this._doSomething() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |