Skip to content

Instantly share code, notes, and snippets.

View Dodotree's full-sized avatar

Olga, Paul & Veny T. Dodotree

  • Mountain View, CA
View GitHub Profile
@Dodotree
Dodotree / federalHolidaysOfTheYear.js
Last active January 10, 2023 05:40
Generates dates of federal holidays for the given year (USA)
function federalHolidaysYear(year){
/* Month counts from 0, week counts from Sunday 0, week day number in the month also from 0 */
/* "Last week day on the month" is the next month week day with num=-1 */
var holidays = [{name: "New Year's Day", fixed: true, mo: 0, date: 1},
{name: "Birthday of Martin Luther King, Jr.", fixed: false, mo: 0, weekDay: 1, num: 2},
{name: "Washington's Birthday", fixed: false, mo: 1, weekDay: 1, num: 2},
{name: "Memorial Day", fixed: false, mo: 5, weekDay: 1, num: -1},
{name: "Juneteenth National Independence Day", fixed: true, mo: 5, date: 19},
{name: "Independence Day", fixed: true, mo: 6, date: 4 },
{name: "Labor Day", fixed: false, mo: 8, weekDay: 1, num: 0},
@Dodotree
Dodotree / throttle.js
Last active November 23, 2022 18:23
Minimalistic JS throttle function to limit calls to any callback function to "once per Nms", most useful with N between 100-300. Can be used on the back end too depending on time delay functions available.
const throttle = (delayFunc, cancelFunc) => (callback, delay) => {
let lastFunc
let lastExecTime
return function (...args) {
const context = this
const elapsed = Date.now() - lastExecTime
function execCallback () {
lastExecTime = Date.now()
@Dodotree
Dodotree / vanilla_time_funcs.js
Created July 11, 2021 05:17
Js small time lapse printing and detection of saving time on top of time zone difference
//Example: timeLapseToString(new Date()-t0);
function timeLapseToString(lapse_int) {
let lapse = new Date(lapse_int);
return `${lapse.getUTCHours()}:${lapse.getUTCMinutes()}:${lapse.getUTCSeconds()}`;
}
function getSavingTimeMin() {
let mins = (new Date("Thu, 01 Jan 1970 00:00:00") - new Date("Thu, 01 Jan 1970 00:00:00 GMT"))/(60*1000);
let ofs = new Date().getTimezoneOffset();
@Dodotree
Dodotree / bestFitAngle.py
Created May 15, 2018 23:50
Blender3D script to find best fit box angle
import bpy, bmesh
from mathutils.geometry import box_fit_2d
'''
After rotation bounding box will have minimum volume
'''
def changeToBestFitAngle(id):
obj = selectAndActivate(id)
bpy.ops.object.mode_set(mode='EDIT')
@Dodotree
Dodotree / blender_select_activate.py
Last active May 15, 2018 23:43
Select and activate object in Blender3D
import bpy
'''
Don't do it if you can avoid it
'''
def selectAndActivate(id):
bpy.ops.object.select_all(action='DESELECT')
bpy.data.objects[id].select = True
obj = bpy.context.selected_objects[0]
import bpy, bmesh
from mathutils import Vector
'''
For simple situations where boxes are not rotated and you only need to detect overlap in bounding boxes
'''
def boundingBoxCollide(c1, c2):
bb = [c1.matrix_world * Vector(corner) for corner in c1.bound_box]
bb2 = [c2.matrix_world * Vector(corner2) for corner2 in c2.bound_box]
import bpy, bmesh
from mathutils import Vector
'''
Several problems solved:
1) no need to activate or select the object
2) no need to change origin after bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
3) only 2 walls to check inside
'''
@Dodotree
Dodotree / bootstrapFileLoaderWithProgressBar.txt
Last active April 15, 2018 00:19
Simple bootstrap4 file uploader with progress bar
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap file loader with progress bar</title>
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css"
<div class="progress fade">
<div class="progress-bar bg-info" role="progressbar" style="width: 0%;"
aria-valuenow="0"
aria-valuemin="0"
#!/usr/bin/perl
use strict;
use Data::Dumper;
my @tst = ( [1,2], 3, [4, [5,6], 7] );
print Dumper(\@tst);
my @flat = @{flatten(\@tst)};
print Dumper(\@flat);