Skip to content

Instantly share code, notes, and snippets.

@keithics
keithics / startDropMarkerAnimation.kt
Last active April 17, 2024 01:56
Animated Drop Marker Kotlin
private fun startDropMarkerAnimation(marker: Marker) {
val target = marker.position
val handler = Handler()
val start = SystemClock.uptimeMillis()
val proj = mMap!!.projection
val targetPoint = proj.toScreenLocation(target)
val duration = (200 + targetPoint.y * 0.6) as Double
val startPoint = proj.toScreenLocation(marker.position)
startPoint.y = 0
val startLatLng = proj.fromScreenLocation(startPoint)
@Kludex
Kludex / main.py
Last active April 17, 2024 01:55
Document each version on FastAPI
from fastapi import APIRouter, FastAPI
from utils import create_versioning_docs
app = FastAPI(docs_url=None, redoc_url=None)
v1_router = APIRouter(prefix="/v1")
v2_router = APIRouter(prefix="/v2")
'''
Exposes the MayaPyManager class, which is used to run instances of MayaPy with explict control over paths and environment variables. A Manager can run scripts, modules, or command strings in a separate MayaPy environment; results and errors are captured and returned.
Typical uses might be:
- running unit tests
- running a copy of Maya.standalone as a headless RPC server with StandaloneRPC https://github.com/theodox/standaloneRPC
- spawning multipe copies of maya to batch process files in parallel on a multi-core machine
- do any of the above on multiple maya versions concurrently
@lacerda1109
lacerda1109 / code.js
Last active April 17, 2024 01:51
Filter shared people from search people "response"
let filteredPeople = [{id: 1, name: "Ana"}, {id: 2, name: "Bia"}, {id: 3, name: "Leo"}, {id: 4, name: "Bruno"}];
let sharedPeople = [{id: 3, name: "Leo"}, {id: 4, name: "Bruno"}];
filteredPeople = filteredPeople.filter(person => {
if (!sharedPeople.find(el => el.id === person.id)) return person;
})
console.log(filteredPeople)
function colorContrast(
hexcolor: string,
cb: (luminance: number) => string, // recommended luminance: 158
) {
if (hexcolor.slice(0, 1) === "#") {
hexcolor = hexcolor.slice(1);
}
const r = parseInt(hexcolor.substr(0, 2), 16);
const g = parseInt(hexcolor.substr(2, 2), 16);
@wpcarro
wpcarro / retry_loop.py
Created October 29, 2019 17:37
Simple retry loop in python with error simulation.
import random
def danger():
if random.choice([True, False]):
raise Exception
def main():
"""Attempt to loop `loop_count` times. Simulate random errors and create a
const symbols = '@#$%&*!-_';
type PasswordConfig = {
amount: number;
lowercase?: boolean;
uppercase?: boolean;
numbers?: boolean;
symbols?: boolean;
};
@rb-cesar
rb-cesar / getUniqueItemArray.ts
Created April 3, 2022 05:38
Remove duplicate items from array
export function getUniqueItemArray<T = any>(list: T[]) {
return list.filter((value, index, array) => array.indexOf(value) === index);
}
@rb-cesar
rb-cesar / InferType.ts
Created April 3, 2022 05:46
Extract the return type from a function type:
type InferType<T> = T extends (infer U)[]
? U
: T extends (...args: any[]) => infer U
? U
: T extends Promise<infer U>
? U
: T;
@rb-cesar
rb-cesar / colorContrast.js
Last active April 17, 2024 01:51
detect background color to apply reverse color
export function colorContrast(
hexcolor: string,
cb: (luminance: number) => string, // recommended luminance: 158
) {
if (hexcolor.slice(0, 1) === "#") {
hexcolor = hexcolor.slice(1);
}
const r = parseInt(hexcolor.substr(0, 2), 16);
const g = parseInt(hexcolor.substr(2, 2), 16);