Skip to content

Instantly share code, notes, and snippets.

View diogobaltazar's full-sized avatar

diogo diogobaltazar

  • Novo Nordisk
  • United Kingdom
View GitHub Profile
# python
> (_, _, x) = [1, 2, 3] # not with len > 3
> x
3
// js
> (([head, ...tail]) => tail.concat(head))([1, 2, 3, 4, 5])
# python
> print (lambda _: _.format(_))('+{}+')
"++{}++"

> print "{a} and {b}".format(b = 'b', a = 'a')
"a and b"
@diogobaltazar
diogobaltazar / src.md
Last active January 20, 2019 17:50
filter | map | reduce
// js

//***************************************************************************
// USE CASE
// 
// SUM first 100 even integers
//***************************************************************************

n = [...Array(100).keys()]      // get indexes starting at 0
// js
> ((x, y) => (w => w + x + y)(0))(1, 2)
3
# python
> print (lambda x, y: (lambda w : w + x + y)(0))(1, 2)
3
@diogobaltazar
diogobaltazar / src.js
Last active January 25, 2019 14:33
objects | create | clone | get attributes subset | destructuring
> [{a:1}, {b:2}, {c:3}].reduce((acc, o) => {return Object.assign(acc, o)}, {})
{a: 1, b: 2, c: 3}
> e = {a: 1}
> e = {...e, b: 1}
{a: 1, b: 2}
// Creating object attributes with names of array elements
> arr = ['a', 'b', 'c']
> Object.assign(...arr.map((attr, index) => {return {[attr]: index}}), {})
@diogobaltazar
diogobaltazar / js.js
Last active December 18, 2018 21:50
Map array to array of objects | JS
> [1, 2, 3].map((_, e) => {return {[e]:e}}) // or simply e => ...
[{…}, {…}, {…}]
0: {1: 1}
1: {2: 2}
2: {3: 3}
> a = {b: {c: {}}}
> a.b.c["d"] = a
> a
b:
db.system.js.save({
_id: 'prt'
, value: (...args) => {
args.forEach(arg =>
printjson({ [arg[0] + '_COMP_ATTR_NAME']: 0 })
)
}
})
//*********************************************
db.system.js.save({
_id: 'prt'
, value: (...args) => {
args.forEach(arg =>
printjson(arg)
)
}
})
// ******************************************
// js NONE
-- haskell
> sum [x | x <- [1..10]]
if ((var as = Item.GetValue(TAXA_FIXA_IRS)) == "Sim")
{
SetValueAndVisible(tbcpercentagemirs, PERCENTAGEM_IRS, WebControlType.TableCell);
}