Skip to content

Instantly share code, notes, and snippets.

View djleonskennedy's full-sized avatar
🌌
Loading...

Yuriy Yakovenko djleonskennedy

🌌
Loading...
View GitHub Profile
@Fredx87
Fredx87 / sync-control.directive.spec.ts
Created August 22, 2018 17:57
Angular SyncControl directive
import { Component } from '@angular/core';
import { async, TestBed } from '@angular/core/testing';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { By } from '@angular/platform-browser';
import { SyncControlDirective } from './sync-control.directive';
class FormGroupHostComponent {
formGroup = new FormGroup({
ctrl: new FormControl('')
});
@leofavre
leofavre / waitInPromise.js
Last active January 20, 2019 23:01
Delays the chaining of a promise by a specified time in milliseconds.
/**
* Part of [Canivete](http://canivete.leofavre.com/#waitinpromise)
*
* Delays the chaining of a promise by a specified
* time in milliseconds.
*
* The function is curried so as to be used inside
* the `.then()` method, passing along the resolved
* value from the previous promise step to the next.
*
@ljharb
ljharb / array_iteration_thoughts.md
Last active April 22, 2024 10:15
Array iteration methods summarized

Array Iteration

https://gist.github.com/ljharb/58faf1cfcb4e6808f74aae4ef7944cff

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it mu

@fernandohu
fernandohu / Reading configuration files before application startup in Angular2 final release.md
Last active May 8, 2023 16:40
Reading configuration files before application startup in Angular2 final release

Reading data before application startup in Angular 2

In this demonstration I will show you how to read data in Angular2 final release before application startup. You can use it to read configuration files like you do in other languages like Java, Python, Ruby, Php.

This is how the demonstration will load data:

a) It will read an env file named 'env.json'. This file indicates what is the current working environment. Options are: 'production' and 'development';

b) It will read a config JSON file based on what is found in env file. If env is "production", the file is 'config.production.json'. If env is "development", the file is 'config.development.json'.

const service = {
getUsers: () => fetch(`https://jsonplaceholder.typicode.com/users`),
getGroups: () => fetch(`https://jsonplaceholder.typicode.com/posts`)
};
async function getData() {
try {
const peoplePromise = await service.getUsers();
const groupsPromise = await service.getGroups();
@maciekish
maciekish / resetXcode.sh
Created August 10, 2016 10:13
Reset Xcode. Clean, clear module cache, Derived Data and Xcode Caches. You can thank me later.
#!/bin/bash
killall Xcode
xcrun -k
xcodebuild -alltargets clean
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$(whoami)/ModuleCache"
rm -rf ~/Library/Developer/Xcode/DerivedData/*
rm -rf ~/Library/Caches/com.apple.dt.Xcode/*
open /Applications/Xcode.app
@mauriciosoares
mauriciosoares / doubleclick.js
Created October 19, 2015 20:07
rxjs double click example
let clickStream = Rx.Observable.fromEvent(document.getElementById('link'), 'click');
clickStream
.buffer(clickStream.debounce(250))
.map(list => list.length)
.filter(x => x === 2)
.subscribe(() => {
console.log('doubleclick');
})
@darrenscerri
darrenscerri / Middleware.js
Last active July 11, 2023 02:59
A very minimal Javascript (ES5 & ES6) Middleware Pattern Implementation
var Middleware = function() {};
Middleware.prototype.use = function(fn) {
var self = this;
this.go = (function(stack) {
return function(next) {
stack.call(self, function() {
fn.call(self, next.bind(self));
});
@learncodeacademy
learncodeacademy / pubsub.js
Created July 29, 2015 02:54
Basic Javascript PubSub Pattern
//events - a super-basic Javascript (publish subscribe) pattern
var events = {
events: {},
on: function (eventName, fn) {
this.events[eventName] = this.events[eventName] || [];
this.events[eventName].push(fn);
},
off: function(eventName, fn) {
if (this.events[eventName]) {
@adriengibrat
adriengibrat / Object.prototype.watch.js
Last active April 23, 2020 19:24
Object.prototype.watch "polyfill"
/**
* Object.prototype.watch polyfill
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/watch
*
* Known limitations:
* - `delete object[property]` will remove the watchpoint
*
* Based on Eli Grey gist https://gist.github.com/eligrey/384583
* Impovements based on Xose Lluis gist https://gist.github.com/XoseLluis/4750176
* This version is optimized for minification