Skip to content

Instantly share code, notes, and snippets.

View dima1034's full-sized avatar
🎯
Focusing

Dmytro Ostapenko dima1034

🎯
Focusing
  • semicolon; vytvir
  • Lviv, Ukraine
  • 23:49 (UTC +03:00)
View GitHub Profile

This describes the common mistake with using closures in JavaScript.

A function defines a new environment

Consider:

function makeCounter()
{
  var obj = {counter: 0};
@dima1034
dima1034 / index.js Capture DOM element screenshot using Chrome headless
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Adjustments particular to this page to ensure we hit desktop breakpoint.
page.setViewport({width: 1000, height: 600, deviceScaleFactor: 1});
await page.goto('https://www.chromestatus.com/samples', {waitUntil: 'networkidle'});
@dima1034
dima1034 / angularjs_directive_attribute_explanation.md
Created January 25, 2018 12:10 — forked from CMCDragonkai/angularjs_directive_attribute_explanation.md
JS: AngularJS Directive Attribute Binding Explanation

AngularJS Directive Attribute Binding Explanation

When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.

  1. Raw Attribute Strings

    <div my-directive="some string" another-param="another string"></div>
@dima1034
dima1034 / cloudSettings
Last active February 9, 2018 11:44
Visual Studio Code Settings Sync Gist
{"lastUpload":"2018-02-09T11:44:19.004Z","extensionVersion":"v2.8.7"}
@dima1034
dima1034 / class_decorator.ts
Created March 19, 2018 15:27 — forked from remojansen/class_decorator.ts
TypeScript Decorators Examples
function logClass(target: any) {
// save a reference to the original constructor
var original = target;
// a utility function to generate instances of a class
function construct(constructor, args) {
var c : any = function () {
return constructor.apply(this, args);
}
@dima1034
dima1034 / class_decorator.ts
Created March 19, 2018 15:27 — forked from remojansen/class_decorator.ts
TypeScript Decorators Examples
function logClass(target: any) {
// save a reference to the original constructor
var original = target;
// a utility function to generate instances of a class
function construct(constructor, args) {
var c : any = function () {
return constructor.apply(this, args);
}
@dima1034
dima1034 / uuid4.js
Created August 16, 2018 11:36 — forked from hugowetterberg/uuid4.js
Simple "spec-driven" v4 UUID implementation
// Version 4 UUIDs have the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx where
// x is any hexadecimal digit and y is one of 8, 9, A, or B (e.g.,
// f47ac10b-58cc-4372-a567-0e02b2c3d479).
// See: http://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29
function uuid() {
var reservedBitValues = ['8','9','a','b'];
return Array.prototype.map.call("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx", function mapUUID(c) {
if (c == "x") {
return Math.round(Math.random()*16-0.5).toString(16);
}
@dima1034
dima1034 / semantic-commit-messages.md
Created September 8, 2018 10:07 — forked from joshbuchea/semantic-commit-messages.md
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@dima1034
dima1034 / semantic-commit-messages.md
Created September 8, 2018 10:07 — forked from joshbuchea/semantic-commit-messages.md
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example