This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
''' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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); |