Skip to content

Instantly share code, notes, and snippets.

View hk-skit's full-sized avatar
👨‍💻
On deep learning mode.

Hitesh Kumar hk-skit

👨‍💻
On deep learning mode.
View GitHub Profile
@joshuabradley012
joshuabradley012 / Object collisions with canvas
Last active January 26, 2024 07:56
An example of 2D collisions using JavaScript Canvas
class State {
constructor(display, actors) {
this.display = display;
this.actors = actors;
}
update(time) {
/**
* provide an update ID to let actors update other actors only once
<!DOCTYPE html>
<meta charset=utf-8>
<meta name=viewport content="width=device-width, initial-scale=1">
<title>#merryCSSmas bundle</title>
<style>
* {
box-sizing: border-box;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
@gaearon
gaearon / prepack-gentle-intro-1.md
Last active May 3, 2024 12:56
A Gentle Introduction to Prepack, Part 1

Note:

When this guide is more complete, the plan is to move it into Prepack documentation.
For now I put it out as a gist to gather initial feedback.

A Gentle Introduction to Prepack (Part 1)

If you're building JavaScript apps, you might already be familiar with some tools that compile JavaScript code to equivalent JavaScript code:

  • Babel lets you use newer JavaScript language features, and outputs equivalent code that targets older JavaScript engines.

Strings

String.prototype.*

None of the string methods modify this – they always return fresh strings.

  • charAt(pos: number): string ES1

    Returns the character at index pos, as a string (JavaScript does not have a datatype for characters). str[i] is equivalent to str.charAt(i) and more concise (caveat: may not work on old engines).

// Array hug, one array hugs the other
// If the hugger is odd numbered, more in the front
Array.prototype.hug = function(arr){
let hugged = this.slice(0,Math.ceil(this.length/2));
hugged.push(...arr);
hugged.push(...this.slice(Math.ceil(this.length/2), this.length));
return hugged;
}
// Array spoon, one array spoons the other
function logColor(color, args) {
console.log(`%c ${args.join(' ')}`, `color: ${color}`);
}
const log = {
aliceblue: (...args) => { logColor('aliceblue', args)},
antiquewhite: (...args) => { logColor('antiquewhite', args)},
aqua: (...args) => { logColor('aqua', args)},
aquamarine: (...args) => { logColor('aquamarine', args)},
azure: (...args) => { logColor('azure', args)},
var str = 'class ಠ_ಠ extends Array {constructor(j = "a", ...c) {const q = (({u: e}) => {return { [`s${c}`]: Symbol(j) };})({});super(j, q, ...c);}}' +
'new Promise((f) => {const a = function* (){return "\u{20BB7}".match(/./u)[0].length === 2 || true;};for (let vre of a()) {' +
'const [uw, as, he, re] = [new Set(), new WeakSet(), new Map(), new WeakMap()];break;}f(new Proxy({}, {get: (han, h) => h in han ? han[h] ' +
': "42".repeat(0o10)}));}).then(bi => new ಠ_ಠ(bi.rd));';
try {
eval(str);
} catch(e) {
alert('Your browser does not support ES6!')
}

FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.


Effective Engineer - Notes

What's an Effective Engineer?