Skip to content

Instantly share code, notes, and snippets.

View json2d's full-sized avatar
🙂
try your baz!

Jason Yung json2d

🙂
try your baz!
View GitHub Profile
@json2d
json2d / Maff.gd
Last active September 17, 2023 14:51
static func Basis(from: Vector3, to: Vector3) -> Basis:
if from.is_equal_approx(to): # then let it be
return
var axis = to.cross(from).normalized() # right-handed
var angle = -to.angle_to(from) # negates to force right-handed orientation
return Basis(axis, angle)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@json2d
json2d / prom-exec-order.js
Created August 2, 2019 16:13
promise execution order
let prom = new Promise(res => {
console.log('A')
setTimeout(res,1000)
})
prom.then(res => {
console.log('B')
})
console.log('C')
@json2d
json2d / enzyme_render_diffs.md
Created July 29, 2019 19:20 — forked from fokusferit/enzyme_render_diffs.md
Difference between Shallow, Mount and render of Enzyme

Shallow

Real unit test (isolation, no children render)

Simple shallow

Calls:

  • constructor
  • render
@json2d
json2d / rxjs - lowlevel.md
Created July 26, 2019 17:48
more technical notes about rxjs

Building observables:

  • Primitives (a.k.a. Kinds of things):
    • Observable:
      • A (subscription) function that takes in an observer, sets up some connections to a data source, and returns a function that can be called to unsubscribe.
        • The actual implementation of Observable is not the subscribe function, but has the subscribe function as a method. It's kind of like how you can make something that represents a function and then say, "But to call it, you need to call its .run method."
        • The actual implementation returns a Subscription object, not an unsubscribe function.
      • Can have a cleanup function internally.
        • Should be called upon unsubscription (cancelling the Observable).
        • Should be called upon error or complete from the data source.
  • next should not be called after it.
@json2d
json2d / state-arg-reselect.js
Last active February 9, 2020 03:56
proposal to put state into callback scope through 'this'
const entryByIdSelector = (state) => state.todos.entrybyId
const recentIdsSelector = (state) => state.todos.recentIds
const entrySelector = _.memoize(
(id) => createSelector(
entryByIdSelector,
(entryById) => entryById[id]
)
)
@json2d
json2d / git-submodule-rm
Last active September 13, 2018 06:27
removing a git submodule binding properly w/o deleting files https://stackoverflow.com/questions/1260748/how-do-i-remove-a-submodule
#!/bin/bash
mv $1 $1_tmp
git submodule deinit -f -- $1
rm -rf .git/modules/$1
git rm -f $1
# Note: a/submodule (no trailing slash)
# or, if you want to leave it in your working tree and have done step 0
@json2d
json2d / poker.js
Created June 19, 2018 20:51
Poker hand classification and comparison
// [{suit:1,val:2}] -> 2 of diamonds
function isFlush(a) {
let suit, result = true;
for(var i=0; i<a.length;i++){ //should use a forloop to break early
const card = a[i]
if(suit===undefined) {
suit = card.suit
}else if(suit !== card.suit){
return false
public static T Func<T>(T a, T b){
return new T(a + b);
}
public static void Main() {
print ("1 + 2 = " + Func (1, 2));
print ("\"1\" + \"2\" = " + Func ("1", "2"));
}
@json2d
json2d / question.md
Last active November 16, 2017 17:57
What is the name for the class of functions designed to be bound dynamically when called?

ES7 [function bind syntax][1] will add the :: operator for working with these kind of functions:

/* ES7 */
import { map, takeWhile, forEach } from "iterlib";

getPlayers()
::map(x => x.character())

::takeWhile(x => x.strength > 100)