Skip to content

Instantly share code, notes, and snippets.

View ar5had's full-sized avatar
🎯
Focusing

Arshad Khan ar5had

🎯
Focusing
View GitHub Profile
@ar5had
ar5had / debounce.ts
Created October 10, 2022 13:41 — forked from ca0v/debounce.ts
Typescript Debounce
// ts 3.6x
function debounce<T extends Function>(cb: T, wait = 20) {
let h = 0;
let callable = (...args: any) => {
clearTimeout(h);
h = setTimeout(() => cb(...args), wait);
};
return <T>(<any>callable);
}
@ar5had
ar5had / Local PR test and merge.md
Created October 29, 2017 15:47 — forked from adam-p/Local PR test and merge.md
Testing a pull request, then merging locally; and avoiding TOCTOU

It's not immediately obvious how to pull down the code for a PR and test it locally. But it's pretty easy. (This assumes you have a remote for the main repo named upstream.)

Getting the PR code

  1. Make note of the PR number. For example, Rod's latest is PR #37: Psiphon-Labs/psiphon-tunnel-core#37

  2. Fetch the PR's pseudo-branch (or bookmark or rev pointer whatever the word is), and give it a local branch name. Here we'll name it pr37:

$ git fetch upstream pull/37/head:pr37
@ar5had
ar5had / ReactIgnore
Created July 25, 2017 14:45 — forked from alexeisavca/ReactIgnore
A simple component to make ReactJs ignore subtrees
var React = require('react/addons');
var ReactIgnore = {
displayName: 'ReactIgnore',
shouldComponentUpdate (){
return false;
},
render (){
return React.Children.only(this.props.children);
}
@ar5had
ar5had / gist:5bb796b1f07fc9046ddaa10e78c152be
Created May 25, 2017 09:16 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@ar5had
ar5had / JSFirst.md
Created May 11, 2017 15:51 — forked from rtoal/JSFirst.md
JSFirst

JS First

About This Manifesto

Have you ever argued for or against teaching language X as the first language in a university computer science curriculum? If so, I hope that your arguments:

  • were first and foremost about students, not about your personal language preferences (in other words, you should answer the question “What do we want students to gain from their experience with a first language?”, not “Is language X better than language Y?” because people hate that latter question);
  • kept in mind that ultimately we want to train polyglots, so the first language is never the only language; and
  • took into account previous work from computing educators, and education theorists and practitioners in general.
ּ_בּ
בּ_בּ
טּ_טּ
כּ‗כּ
לּ_לּ
מּ_מּ
סּ_סּ
תּ_תּ
٩(×̯×)۶
٩(̾●̮̮̃̾•̃̾)۶
@ar5had
ar5had / deepCopy.js
Created March 11, 2017 13:32 — forked from azurite/deepCopy.js
Quick and dirty way to deep copy json objects in javascript (object prototypes are not copied)
function isNull(v) {
return typeof v === "object" && !v;
}
function isPrimitive(v) {
return ["number", "string", "boolean", "undefined"].indexOf(typeof v) !== -1 || isNull(v);
}
function isPlainObject(o) {
return o && typeof o === "object" && o.constructor === Object;
@ar5had
ar5had / mongoose-connection-options.js
Created January 20, 2017 07:17
mLab recommended mongoose connection options. More supported connections for the underlying Node Native driver can be found here: http://mongodb.github.io/node-mongodb-native/
// mongoose 4.3.x
var mongoose = require('mongoose');
/*
* Mongoose by default sets the auto_reconnect option to true.
* We recommend setting socket options at both the server and replica set level.
* We recommend a 30 second connection timeout because it allows for
* plenty of time in most operating environments.
*/
var options = { server: { socketOptions: { keepAlive: 300000, connectTimeoutMS: 30000 } },

Parens And Performance

Years ago, some smart folks that worked on JS engines realized that not all JS that's loaded into a page/app initially is needed right away. They implemented JIT to optimize this situation.

JIT means Just-In-Time, which means essentially that the engine can defer processing (parsing, compiling) certain parts of a JS program until a later time, for example when the function in question is actually needed. This deferral means the engine is freer to spend the important cycles right now on the code that's going to run right now. This is a really good thing for JS performance.

Some time later, some JS engine devs realized that they needed to get some hints from the code as to which functions would run right away, and which ones wouldn't. In technical speak, these hints are called heuristics.

So they realized that one very common pattern for knowing that a function was going to run right away is if the first character before the function keyword was a (, because that usually m

@ar5had
ar5had / hex-opacity-values.txt
Created January 3, 2017 10:45 — forked from frankyonnetti/CSS--hex-opacity-values.css
#css Hex Opacity Values
Hex Opacity Values
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6