Skip to content

Instantly share code, notes, and snippets.

View felipeblassioli's full-sized avatar
🏠
Working from home

Felipe Blassioli felipeblassioli

🏠
Working from home
  • Brazil, São Paulo
View GitHub Profile
@felipeblassioli
felipeblassioli / etude-ts-defaultoptions.md
Created June 23, 2024 17:48
etude-ts-default-options

Merging options and defaults

  1. Use the spread operator with type inference:
export function cache<T extends (...args: any[]) => any, KeyType, ResultType, ErrorType>(
  fn: T,
  options: Partial<ICacheOptions<KeyType, ResultType, ErrorType>> = {}
): T {
  const mergedOptions: ICacheOptions<KeyType, ResultType, ErrorType> = {
//
// Études: Quirks and Implications of Numbers in JavaScript
//
// Reading:
// - [Here is what you need to know about JavaScript’s Number type - Max Koretskyi](https://medium.com/angular-in-depth/javascripts-number-type-8d59199db1b6)
// Quotes:
// > Why 0.1+0.2 IS NOT equal to 0.3 and 9007199254740992 IS equal to 9007199254740993
//
// > According to the ECMAScript standard, there is only one type for numbers and it is the ‘double-precision 64-bit
// > binary format IEEE 754 value’. This type is used to store both integers and fractions and is the equivalent of `double`
@felipeblassioli
felipeblassioli / etude-writing-decorators-in-javascript-node.md
Last active April 7, 2024 03:17
étude: "decorators" in javascript

Coming from Python I wanted to write something like this:

@trace('name', opts)
def business_logic(foo, bar):
   return 0

To use opentelemetry in specific function and having goodies like putting relevant stuff in the context.

@felipeblassioli
felipeblassioli / typeprojection.scala
Created October 4, 2023 03:10
Scala2 and Scala3 type projections test
trait Logger {
protected def formatMessage(message: String): String
def log(message: String): Unit = {
println(formatMessage(message))
}
// Nested case class inside the trait
case class LogEntry(timestamp: Long, content: String)
}
@felipeblassioli
felipeblassioli / python_performance_loops_vs_itertools.py
Last active July 15, 2016 15:20
Python 2.7 itertools.product vs nested for loops vs nested for comprehension
import timeit
def test_performance(code, setup='pass', TIMES=10):
avg = lambda l: sum(l)/len(l)
result = timeit.Timer(code, setup).repeat(3,10)
print avg(result)
NESTED_FOR = """
for x in xrange(1000):
for y in xrange(1000):
var usersStream = Bacon.interval(3000)
.filter(function(){ return this.state.mode === "users" }.bind(this))
.flatMapLatest(function(){
var store = this.state.selectedStore;
return Bacon.fromPromise( $.ajax({
type: 'GET',
url: '/users/',
data: {store_id: store.id}
}) );
}.bind(this))
@felipeblassioli
felipeblassioli / show_features_keypoints.py
Last active December 19, 2016 05:05
OpenCV 2.4.10 - Show keypoints of all available feature detectors. Some filters applied: Grayscale, Thresholding and canny.
# -*- coding: utf-8 -*-
import cv2
import numpy as np
feature_detectors = [
"FAST",
"STAR",
"SIFT",
"SURF",
"ORB",
@felipeblassioli
felipeblassioli / gist:d7abf0373859eb9895fd
Created February 13, 2015 16:39
Related_recipes funcionando
POST http://rms-prep-sa.foodity.com/api/v2/recipes
Request BODY BEGIN
p_ingredients=tomato&fields=recipe_id%2Ctitle%2Cshort_title%2Cingredients%2Cmethods%2Cserves%2Ccook_time%2Cdifficulties%2Cassets%2Crelated_recipes&api_key=9HSRMDKDKXSSSLD4IOJJQHJMADRBWB&lang=en-GB&page_size=20
Request BODY END
Response:
{
"page_start": 0,
"data": [
{
@felipeblassioli
felipeblassioli / gist:0acad63409682aae98d9
Created February 13, 2015 16:16
Solicitando receitas com p_ingredients=Tomato,Onion
POST http://rms-prep-sa.foodity.com/api/v2/recipes
Request BODY BEGIN
p_ingredients=tomato%2Conion&fields=recipe_id%2Ctitle%2Cshort_title%2Cingredients%2Cmethods%2Cserves%2Ccook_time%2Cdifficulties%2Cassets&api_key=9HSRMDKDKXSSSLD4IOJJQHJMADRBWB&lang=en-GB&page_size=20
Request BODY END
Response:
{
"page_start": 0,
"data": [
{
@felipeblassioli
felipeblassioli / gist:910d943f676c5a8be3f2
Created February 13, 2015 16:15
Solicitando receitas com p_ingredients = Tomato
POST http://rms-prep-sa.foodity.com/api/v2/recipes
Request BODY BEGIN
p_ingredients=tomato&fields=recipe_id%2Ctitle%2Cshort_title%2Cingredients%2Cmethods%2Cserves%2Ccook_time%2Cdifficulties%2Cassets&api_key=9HSRMDKDKXSSSLD4IOJJQHJMADRBWB&lang=en-GB&page_size=20
Request BODY END
Response:
{
"page_start": 0,
"data": [
{