Skip to content

Instantly share code, notes, and snippets.

View NoFishLikeIan's full-sized avatar
🦉
night owling

Andrea NoFishLikeIan

🦉
night owling
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@NoFishLikeIan
NoFishLikeIan / conditional_on.py
Created April 5, 2019 09:37
A simple python decorator that prevents calling functions if other class attributes are not set. Beware this breaks the "Errors should never pass silently" rule!
from functools import wraps
def has_all_attr(self, *attribute_names):
'''
An aid function to determine the condition of "not calling", this could be a parameter of conditional on potentially
'''
return all((hasattr(self, attr) and getattr(self, attr) is not None) for attr in attribute_names)
@NoFishLikeIan
NoFishLikeIan / mock_data.json
Last active April 8, 2019 16:00
Mocked data from mockaroo
[{"id":1,"height":180,"gender":"Male","city":"Ansongo","weight":185.65,"dateOfMeasure":"7/22/2018"},
{"id":2,"height":190,"gender":"Male","city":"Huurch","weight":182.28,"dateOfMeasure":"10/26/2018"},
{"id":3,"height":198,"gender":"Male","city":"Portelândia","weight":190.85,"dateOfMeasure":"8/19/2018"},
{"id":4,"height":189,"gender":"Female","city":"Wangchang","weight":145.82,"dateOfMeasure":"6/18/2018"},
{"id":5,"height":162,"gender":"Female","city":"Kamenka","weight":128.84,"dateOfMeasure":"2/16/2019"},
{"id":6,"height":183,"gender":"Female","city":"Ibiporã","weight":130.62,"dateOfMeasure":"1/31/2019"},
{"id":7,"height":197,"gender":"Male","city":"Jinchuan","weight":196.47,"dateOfMeasure":"1/29/2019"},
{"id":8,"height":161,"gender":"Female","city":"Algés","weight":160.29,"dateOfMeasure":"9/2/2018"},
{"id":9,"height":195,"gender":"Male","city":"Karangtalun","weight":179.32,"dateOfMeasure":"9/8/2018"},
{"id":10,"height":188,"gender":"Female","city":"Itu","weight":122.84,"dateOfMeasure":"4/13/2018"},
@NoFishLikeIan
NoFishLikeIan / pixelsOperations.js
Created April 11, 2019 17:54
Some funny pixels operations
function sumPixels(pixelA, pixelB) {
var first = parseInt(pixelA.replace('px', ''))
var second = parseInt(pixelB.replace('px', ''))
return `${first+second}px`
}
function multiplyPixels(pixelString, factor) {
var f = Math.floor(factor)
var remainder = f ? factor % f : factor
@NoFishLikeIan
NoFishLikeIan / composeComponent.js
Last active April 12, 2019 09:38
Accurat suggestion for a decorator
import { observer, inject } from 'mobx-react'
const compose = (...fns) => {
const last = fns.slice(-1)[0]
const decorators = fns.slice(0, -1)
return decorators.reduceRight((v, f) => f(v), last);
}
export const SFComponents = compose(
@NoFishLikeIan
NoFishLikeIan / iterative_dict.py
Created May 19, 2019 17:00
Two utils functions to generate iterative settable dicts.
from typing import List
from collections import defaultdict
def nested_set(nested_dict: defaultdict, path: List[str]) -> defaultdict:
'''
A function that sets a value to a defaultdict given a path of keys.
Example:
d = defaultdict(dict)
d = nested_set(d, ['hello', 'ciao', 3])
@NoFishLikeIan
NoFishLikeIan / struct-config.ts
Created May 29, 2019 14:28
Structural config alternatives
type UnionizeArray<D extends Readonly<Array<string>>> = D[number]
const dimensions = ['x', 'y'] as const
const optionalDimensions = ['color', 'radius'] as const
type numerical = 'x' | 'y' | 'radius'
type _ = 'man' | 'opt'
type __ = 'num' | 'nonum'
@NoFishLikeIan
NoFishLikeIan / random_config.json
Created June 10, 2019 13:30
Configuration for appearance config.
{
"titleFontStyle": {
"color": {
"r": 0,
"g": 0,
"b": 0,
"a": 1
},
"fontFamily": "Times New Roman",
"fontSize": {
@NoFishLikeIan
NoFishLikeIan / main.py
Last active June 25, 2019 17:09
bootstrap-flask
from loguru import logger
from src.server import app, app_config
if __name__ == '__main__':
port = app_config['port']
host = app_config['host']
logger.info(f'Running on {host}:{port}')
app.run(**app_config)
@NoFishLikeIan
NoFishLikeIan / melbourne.csv
Created July 21, 2019 19:16
Mock time series
Date Temp
1981-01-01 20.7
1981-01-02 17.9
1981-01-03 18.8
1981-01-04 14.6
1981-01-05 15.8
1981-01-06 15.8
1981-01-07 15.8
1981-01-08 17.4
1981-01-09 21.8