Skip to content

Instantly share code, notes, and snippets.

Avatar
🤙

Shlomi Assaf shlomiassaf

🤙
View GitHub Profile
@shlomiassaf
shlomiassaf / lazy-drag-drop.ts
Created Nov 15, 2018
Lazy binding between `CdkDrag` and `CdkDropList` + support for non direct draggables in a drop container
View lazy-drag-drop.ts
import { take } from 'rxjs/operators';
import { Input, Directive, ElementRef, QueryList, OnDestroy, Optional, AfterViewInit } from '@angular/core';
import { CdkDropList, CdkDrag, CdkDragHandle, CDK_DROP_LIST_CONTAINER } from '@angular/cdk/drag-drop';
@Directive({
selector: '[cdkLazyDropList]',
exportAs: 'cdkLazyDropList',
providers: [
{ provide: CDK_DROP_LIST_CONTAINER, useExisting: CdkLazyDropList },
],
@shlomiassaf
shlomiassaf / demo.ts
Created May 3, 2018
RxJS cached polling operator with cache invalidation support in 10 LOC.
View demo.ts
const reset$ = new Subject();
// the API call we want to poll
const poller$ = myApi.getData()
.pipe(poll(reset$, 30000)); // 30 secs
// no polling yet...
const sub1 = poller$.subsbribe(data => console.log('POLL TICK 1') );
const sub2 = poller$.subsbribe(data => console.log(' & 2') );
@shlomiassaf
shlomiassaf / angular-general-purpose-template-var-simple.ts
Last active Apr 21, 2018
angular-general-purpose-template-var-simple.ts
View angular-general-purpose-template-var-simple.ts
import { Directive } from '@angular/core';
@Directive({
selector: '[var]',
exportAs: 'var'
})
export class VarDirective {
[key: string]: any;
}
@shlomiassaf
shlomiassaf / angular-general-purpose-template-var.ts
Last active Apr 21, 2018
angular-general-purpose-template-var.ts
View angular-general-purpose-template-var.ts
import { Directive, Input } from '@angular/core';
@Directive({
selector: '[var]',
exportAs: 'var'
})
export class VarDirective {
[key: string]: any;
@Input('var') set assign(value : any) {
@shlomiassaf
shlomiassaf / sync_fork.sh
Last active May 26, 2016
A bash script for automatic sync between a local fork, it's origin and the upstream (on GitHub)
View sync_fork.sh
# Flow:
# Find origin
# Find upstream URL
# Go to master
# Rebase upstream to master
# push changes to origin
# Make sure master has not pending changes for commit
# Some credits to an unknown source...
@shlomiassaf
shlomiassaf / AngularJS-slide-Toggle-(With-cancel-support).markdown
Last active Apr 20, 2017
AngularJS slide Toggle (With cancel support)
View AngularJS-slide-Toggle-(With-cancel-support).markdown
@shlomiassaf
shlomiassaf / CALL DATA
Created Jan 10, 2015
resty-stone creating a new Post.
View CALL DATA
/* The body of the POST call to http://localhost:3000/api/posts */
{
"title": "This is a new post!",
"publishedDate": "2015-01-01T22:00:00.000Z",
"content": {
"brief": "Lets write a simple brief",
"extended": "<p>Maybe some extended info with html tags</p>"
}
}
View gist:43e61b0d7474dbbd7123
function readDir(start, callback) {
// Use lstat to resolve symlink if we are passed a symlink
fs.lstat(start, function(err, stat) {
if(err) {
return callback(err);
}
var found = {dirs: [], files: []},
total = 0,
processed = 0;
function isDir(abspath) {
@shlomiassaf
shlomiassaf / ngGridDynamicEditCellFlag.js
Last active Aug 29, 2015
Dynamic cell editable flag for Angular UI ng-grid using a decorator.
View ngGridDynamicEditCellFlag.js
app.config(function($provide) {
$provide.decorator('ngCellHasFocusDirective', function($delegate) {
var directive = $delegate[0];
var original = directive.compile;
directive.compile = function(element, attrs) {
return function($scope, element) {
// state.
var isOn = false;