Skip to content

Instantly share code, notes, and snippets.

View dwiyatci's full-sized avatar
♨️
Missing Ania 👱🏻‍♀️🇵🇱, so much

Glenn Dwiyatcita dwiyatci

♨️
Missing Ania 👱🏻‍♀️🇵🇱, so much
View GitHub Profile
@dwiyatci
dwiyatci / faketimers-polling-workaround.js
Last active August 8, 2022 17:06
Jest Timers and Promises in polling.
jest.useFakeTimers();
const pollingPromise = poll();
const cancelAdvance = advanceTimersContinuously();
const status = await pollingPromise;
cancelAdvance();
expect(status).toEqual('COMPLETE');
function advanceTimersContinuously() {
@dwiyatci
dwiyatci / xgen-and-gen.js
Last active April 17, 2020 22:44
function* is not a gen.
function* xcounter() {
let index = 0;
while (true) {
index += 1;
const x = yield index;
console.log(x);
}
}
const xgen = xcounter();
@dwiyatci
dwiyatci / favor-factory.js
Last active November 10, 2016 12:51
Favoring factory pattern over constructor pattern in JavaScript
//////////// constructor pattern
function Employee() {
this.name = '';
this.salary = 0; // no real encapsulation of private property
}
// too much code noises and bugs-prone from `prototype` and `this`
Employee.prototype.getSalary = function () {
javascript:void function()%7B(function()%7Bfunction e()%7Bvar e%3Ddocument.createElement("link")%3Be.setAttribute("type","text/css"),e.setAttribute("rel","stylesheet"),e.setAttribute("href",T),e.setAttribute("class",A),document.body.appendChild(e)%7Dfunction t()%7Bfor(var e%3Ddocument.getElementsByClassName(A),t%3D0%3Bt<e.length%3Bt%2B%2B)document.body.removeChild(e%5Bt%5D)%7Dfunction n()%7Bvar e%3Ddocument.createElement("div")%3Be.setAttribute("class",C),document.body.appendChild(e),setTimeout(function()%7Bdocument.body.removeChild(e)%7D,100)%7Dfunction o(e)%7Breturn%7Bheight:e.offsetHeight,width:e.offsetWidth%7D%7Dfunction a(e)%7Bvar t%3Do(e)%3Breturn t.height>p%26%26t.height<b%26%26t.width>w%26%26t.width<v%7Dfunction r(e)%7Bfor(var t%3De,n%3D0%3Bt%3B)n%2B%3Dt.offsetTop,t%3Dt.offsetParent%3Breturn n%7Dfunction i()%7Bvar e%3Ddocument.documentElement%3Breturn window.innerWidth%3Fwindow.innerHeight:e%26%26!isNaN(e.clientHeight)%3Fe.clientHeight:0%7Dfunction s()%7Breturn window.pageYOffset%3Fwindow.pageYOffset:
@dwiyatci
dwiyatci / anticollision-kletternmonkey-2.x.js
Created July 8, 2015 15:38
An anti-collision Kletternmonkey 🙈
// ==UserScript==
// @name anticollision-kletternmonkey
// @namespace localhost
// @description My take on "#MoneyTree - das Kletterduell" campaign by O2 (May-July 2015).
// Just for fun (topping myself in the top ten), and not for
// intentionally winning the contest and/or the "Hauptpreis" -
// Schwedenreise für zwei im Design-Baumhaus (Gesamtwert 3.000 €).
//
// This should also be a case study showing how bad it is when a JS
// programmer carelessly pollutes the global namespace. =)
@dwiyatci
dwiyatci / kfc.de-face.js
Created April 24, 2014 22:20
A monkey script for halal-ing chickens in KFC Deutschland. Just for fun! No offense to the muslim brotherhood. :'p
// ==UserScript==
// @name kfc.de-face
// @creator Glenn Dwiyatcita
// @namespace https://gist.github.com/dwiyatci
// @description A monkey script for halal-ing chickens in KFC Deutschland. Just for fun! No offense to the muslim brotherhood. :'p
// @include http://www.kfc.de/faq
// @version 1
// @grant none
// @require http://code.jquery.com/jquery-latest.min.js
// ==/UserScript==