Skip to content

Instantly share code, notes, and snippets.

@albulescu
albulescu / TypeingListen.ts
Created August 23, 2016 19:17
Listen for passwords while on page
import { Injectable, EventEmitter } from '@angular/core';
@Injectable()
export class TypeingListen extends EventEmitter<boolean> {
private keyStack:string[] = [];
private emptyInterval:any;
constructor( private password:String ) {
@albulescu
albulescu / StyleChangeWatcher.js
Created July 15, 2016 13:18
Angular 2 style change watcher
const watcher = new StyleChangeWatcher();
watcher.watch(element, ["width"]);
watcher.observer.subscribe((event:StyleChangeEvent) => {
console.log('Element:', event.element);
console.log('Change:', event.change.property,':', event.change.previous, '=>', event.change.current);
});
@albulescu
albulescu / gist:82ad75f9f478631734961a0d239b016a
Last active July 13, 2016 13:58
Ng 1.5 to 2 component standard
# Angular 1.5
class Button {
constructor( $http ) {
this.http = $http;
}
}
angular.module('x').component('xbutton', {
...,
controller: Button
});
const flatten = arr => arr.reduce(
(a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []
);
@albulescu
albulescu / download.go
Created March 25, 2016 09:44
golang download file with progress
package main
/**
* @website http://albulescu.ro
* @author Cosmin Albulescu <cosmin@albulescu.ro>
*/
import (
"bytes"
"fmt"
@albulescu
albulescu / test.go
Created February 12, 2016 14:44
Nodes merge and sort
/*
There are sets of node ids which contain partly-contiguous ranges of node ids.
The rst part of the exercise is to (in a language of your choice) model the
ranges in a space ef cient manner.
An example set:
a/1, a/2, a/3, a/4, a/128, a/129, b/65, b/66, c/1, c/10, c/42
Secondly, given the model already developed, write an algorithm that
will add two sets, merging any overlapping ranges.
----- html
<div ng-class="ChatController">
<chat>
<div chat-messages class="messages">
<div chat-message class="message-item">
</div>
</div>
<div class="footer">
@albulescu
albulescu / gist:2c186e66b17212eb8ed7
Last active August 29, 2015 14:17
Manually run chef-solo on instance
echo "cookbook_path [\"/opt/aws/opsworks/current/site-cookbooks\"]" > solo.rb && opsworks-agent-cli get_json > attributes.json && sudo /opt/aws/opsworks/current/bin/chef-solo -c ./solo.rb -j ./attributes.json -o
@albulescu
albulescu / autoscroll.js
Last active August 29, 2015 14:11
Angular AutoScroll Directive
/*
$scope.autoScrollEnabled = true;
$scope.onSendMessage = function() {
// enable autoscrolling in case is disabled by user scroll up
$scope.$emit('$enableAutoScroll');
};
<?php
use Phalcon\Mvc\Micro,
Phalcon\Events\Manager as EventsManager,
Phalcon\Http\Response,
Phalcon\Http\Request;
//Create a events manager
$eventManager = new EventsManager();