Skip to content

Instantly share code, notes, and snippets.

View diogobaltazar's full-sized avatar

diogo diogobaltazar

  • Novo Nordisk
  • United Kingdom
View GitHub Profile
@diogobaltazar
diogobaltazar / src.md
Created February 2, 2019 21:47
Multiple arguments
// js

> f = (...args) => args.length
> f(1, 2, [1, 2])
3
#py
@diogobaltazar
diogobaltazar / src.js
Last active February 5, 2019 21:05
_: map | keyBy | omit | values | merge
> var object = { 'a': 1, 'b': '2', 'c': 3 };
> _.omit(object, ['a', 'c']);
{ 'b': '2' }
> object = { 'a': [{ 'b': 2 }, { 'd': 4 }] }
> other = { 'a': [{ 'c': 3 }, { 'e': 5 }] }
> _.merge(object, other);
{ 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
> a = {b: [{a : 1}, {b: 12}]}
> b = {b: [{b: 67}]}
@diogobaltazar
diogobaltazar / src.md
Last active January 20, 2019 18:47
indirection
# py

> a = 1
> b = 'a'
> eval(b)
1
@diogobaltazar
diogobaltazar / src.py
Last active February 2, 2019 23:30
pandas | series | dataframes | index hierarchy | GroupBy, aggregate functions | Merging, joining, concatenating | operations | IO
import numpy as np
import pandas as pd
> lbls = ['a', 'b', 'c'] # or np.array
> data = [123, 423, 456]
> d = {}
> for i in np.arange(len(lbls)):
> d[lbls[i]] = data[i]
> pd.Series(data = data)
@diogobaltazar
diogobaltazar / src.md
Last active May 25, 2019 14:04
forEach | every | some | any
// js

> keys = [0, 1, 2]
> values = ['a', 'b', 'c']
> obj = {}
> keys.forEach((key, i) => obj[key] => values[i] )
> obj
{0: 'a', 1:'b', 2:'c'}
@diogobaltazar
diogobaltazar / src.md
Last active January 21, 2019 19:32
Declare | Init | Comprehension | shape, reshape | Broadcasting | Matrix operations | Dictionaries
// js
> [1, 2, 3, 4, 5].slice(0, 1) // from index 0 inclusive to index 1 exclusive
[1]
> [1, 2, 3, 4, 5].slice(1, -1)
[2, 3, 4]

// arrays are objects
// js

> ((...a) => a.some(_ => _)) ("", '', 0, false, null, NaN, undefined)
false
> ["", '', 0, false, null, NaN, undefined].some(Boolean)
false
form_data = {}
// evaluating the args out of the if-then clause enables them to be available
// inside the if-then body. They are intended to be evaluated on whether they're
// empty or not, but evaluating them on the if-then condition would not let all
// args be evaluated if at least one but the last was not empty.
lastEvolutionsEdit = {{admin_edit_evolution_txt.text}}
lastRoleEdit = {{admin_edit_role_txt.text}}
lastTrainEdit = {{admin_edit_training_txt.text}}
# py
> def f(a, b = 1):
>     return a + b
> print f(1)
2
# python
if True:
  print 'always'
elif False:
  print 'never'
else:
  print 'never ever'