Skip to content

Instantly share code, notes, and snippets.

View leolanese's full-sized avatar
💻
[] === []; // false ¯\_(ツ)_/¯

Leo Lanese leolanese

💻
[] === []; // false ¯\_(ツ)_/¯
View GitHub Profile
@leolanese
leolanese / gist:9b77fb3dbe6279631f1e4deb68d50cc1
Created January 4, 2024 16:15
Quick Python API using web framework Flask
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/api/intro')
def intro():
return jsonify(message='Hello, World!')
if __name__ == '__main__':
app.run(debug=True)
@leolanese
leolanese / function-pipe.js
Created October 19, 2020 20:57
function pipe
const pipe = (...functions) => args => functions.reduce((arg, fn) => fn(arg), args);
// const league = [
// { heroe: "superman", power: 'fly' },
// { heroe: "batman", power: 'millionare'},
// { heroe: "flash", power: 'speed' },
// ]
// const filter = f => arr => arr.filter(f);
// const map = m => arr => arr.map(m);
const compose = (...functions) => args => functions.reduceRight((arg, fn) => fn(arg), args);
// Example:
// const league = [
// { heroe: "superman", power: 'fly' },
// { heroe: "batman", power: 'millionare'},
// { heroe: "flash", power: 'speed' },
//]
//const filter = f => arr => arr.filter(f);
//const map = m => arr => arr.map(m);
@leolanese
leolanese / Debounce_decorator.js
Created August 19, 2020 07:07
Debounce decorator Angular
/**
* Debounce a method
*/
function debounce(ms) {
return function(target: any, key: any, descriptor: any) {
const oldFunc = descriptor.value
const newFunc = _debounce(oldFunc,ms)
descriptor.value = function() {
return newFunc.apply(this,arguments)
@leolanese
leolanese / fetch-typeScript-async-await.ts
Created August 16, 2020 10:49
fetch API + async-await + TypeScript
// declaring fetch + async-await + TypeScript
export async function get<T>(
path: string,
args: RequestInit = { method: "get" }
): Promise<HttpResponse<T>> {
return await http<T>(new Request(path, args));
};
export async function post<T>(
path: string,
@leolanese
leolanese / debounce.js
Created August 12, 2020 20:39
debounce js
const debounce = (fn, time) => {
let timerId;
return function(...args) {
const functionCall = () => fn.apply(this, args);
clearTimeout(timerId);
timerId = setTimeout(functionCall, time);
};
};
function startCountingForHideAndSeek() {
// State for managing cleanup and cancelling
let finished = false;
let cancel = () => finished = true;
const promise = new Promise((resolve, reject) => {
//
// Custom Promise Logic
//
// NOTE: This countdown not finish in exactly 10 seconds, don't build timers this way!
'use strict';
function swap(arr, ind1, ind2) {
let temp = arr[ind1];
arr[ind1] = arr[ind2];
arr[ind2] = temp;
}
function quickSortInPlace(arr, left, right) {
left = left || 0;
@leolanese
leolanese / gist:dd5a196c183d9fb21942ae4f39a0911c
Created July 2, 2020 15:45
Depth First Search Data Structures algorithm (DFS)
## DFS & BFS:
DFS = storing the vertices "stacks", stacks are LIFO (push, pop).
BFS = storing the vertices "queue", queues are FIFO (shift, unshift or enqueue and dequeue).
## Why to use BFS and DFS?
#### DFS = memory requirements than BFS. It will take a lot of memory to traverse deeper trees while it works well with wider trees.
commonly used when you need to search the entire tree.
#### BFS = is better for deeper trees since it will take a lot more memory to operate on wider trees.
## When to use BFS and DFS?
@leolanese
leolanese / create-react-app-scss
Created June 27, 2020 20:34
Create React App with SCSS (out of the box)
npx create-react-app my-app
cd my-app
yarn add node-sass -S
// Change .css files to .scss
// Change any imports to use .scss
yarn start