Skip to content

Instantly share code, notes, and snippets.

View hoodwink73's full-sized avatar

Arijit Bhattacharya hoodwink73

View GitHub Profile
@hoodwink73
hoodwink73 / getFile.js
Created July 12, 2016 04:22
The thunk way to run parallel asynchronous operation but control the order of the callbacks
function getFile (file) {
var text, fn;
fakeAjax(file, function oldSchoolCb (response) {
if (fn) {
fn(response)
} else {
text = response
}
})
@hoodwink73
hoodwink73 / hideMonkeyPatching.js
Created August 15, 2016 18:46
Middlewares - a way to facilitate third party extension points around a framework's core operations
// original method
function canBeEnhancedLater (x) {
return x
}
// enhancement modules
function double (next) {
return function (x) {
return next(2 * x)
@hoodwink73
hoodwink73 / pingPongInCSP.js
Created December 5, 2016 05:43
Obligatory CSP examples
csp.go(function* () {
// this routine acts
// like the referee
var table = csp.chan();
// two routines represents two players
// they have access to the same channel
csp.go(player, ["ping", table])
csp.go(player, ["pong", table])
@hoodwink73
hoodwink73 / 0_reuse_code.js
Created January 7, 2017 06:45
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@hoodwink73
hoodwink73 / keybase.md
Created February 12, 2017 14:18
Keybase Proof

Keybase proof

I hereby claim:

  • I am hoodwink73 on github.
  • I am arijit (https://keybase.io/arijit) on keybase.
  • I have a public key whose fingerprint is 9113 5960 CE4C A0F0 0F8D 0461 3C99 424A F753 520E

To claim this, I am signing this object:

@hoodwink73
hoodwink73 / error-handling.js
Last active August 22, 2017 04:02
Promises are the power horse of async paradigm in JS
// try-catch blocks cannot handle async errors
function foo() {
setTimeout( function(){
baz.bar();
}, 100 );
}
try {
foo();
// later throws global error from `baz.bar()`
@hoodwink73
hoodwink73 / components.user-card.js
Last active July 12, 2017 08:17
Component Composition
import Ember from 'ember';
export default Ember.Component.extend({
});
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
launchConfirmDialog() {
this.set('confirmShown', true)
},
submitConfirm() {
this.get('onConfirm')(this.get('confirmValue'))
this.set('confirmShown', false)
@hoodwink73
hoodwink73 / async-add-and-placeholder-object.js
Last active August 7, 2017 15:51
wrapper over a state with plain old callbacks
function addAsync (getX, getY) {
var x, y, consumer;
getX(function (xVal) {
if (y !== undefined && consumer !== undefined) {
consumer (xVal + y)
}.else {
x = xVal
}
@hoodwink73
hoodwink73 / components.anti-scroll.js
Last active September 11, 2017 09:27
New Twiddle
import Ember from 'ember';
export default Ember.Component.extend({
didRender () {
this._super(...arguments);
console.log(this.$('.antiscroll-wrap'))
this.$('.antiscroll-wrap').antiscroll({
autoHide: false
});
}