Skip to content

Instantly share code, notes, and snippets.

View shlomiassaf's full-sized avatar
🤙

Shlomi Assaf shlomiassaf

🤙
View GitHub Profile
@shlomiassaf
shlomiassaf / lazy-drag-drop.ts
Created November 15, 2018 23:00
Lazy binding between `CdkDrag` and `CdkDropList` + support for non direct draggables in a drop container
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 19:38
RxJS cached polling operator with cache invalidation support in 10 LOC.
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 April 21, 2018 23:43
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 April 21, 2018 23:43
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 22:31
A bash script for automatic sync between a local fork, it's origin and the upstream (on GitHub)
# 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 April 20, 2017 09:06
AngularJS slide Toggle (With cancel support)
@shlomiassaf
shlomiassaf / CALL DATA
Created January 10, 2015 22:25
resty-stone creating a new Post.
/* 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>"
}
}
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 August 29, 2015 14:04
Dynamic cell editable flag for Angular UI ng-grid using a decorator.
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;