Skip to content

Instantly share code, notes, and snippets.

View olostan's full-sized avatar

Valentyn Shybanov olostan

View GitHub Profile
@olostan
olostan / annotations.ts
Created April 7, 2016 23:18
TypeScript Annotations for Angular 1
function injector(type:string, name:string, values:string[]):any {
return (target:Function) => {
const injectee:Function = (...args:any[]):Object => {
return ((classConstructor:Function, args:any[], ctor:any):Object => {
ctor.prototype = classConstructor.prototype;
const child:Object = new ctor;
const result:Object = classConstructor.apply(child, args);
return typeof result === "object" ? result : child;
})(target, args, () => {
return null;
type BindingType = '<' | '@' | '&' | '=';
interface Bindings {
[property:string]:BindingType
}
export interface IComponentDefinitionObject {
bindings?:Bindings;
controllerAs?:string;
require?;
@olostan
olostan / bindTo.js
Last active March 17, 2016 23:55
Dynamic recompilation
app.directive('bindTo', function($compile) {
return {
scope:false,
restruct:'A',
terminal:true,
priority: 1000,
compile: function(tElem) {
tElem.removeAttr('bind-to');
return function (scope, elem,a) {
var context = a.bindContext;
interface someDataType {
}
export interface IParentComponentConroller {
getSomeData():ng.IPromise<someDataType);
}
class ParentComponentConroller implements IParentComponentConroller {
constructor(private $http);
/**
* Adds a custom menu with items to show the sidebar and dialog.
*
* @param {Object} e The event parameter for a simple onOpen trigger.
*/
function onOpen(e) {
SpreadsheetApp.getUi()
.createAddonMenu()
.addItem('Add Quotes', 'addQuotes')
.addToUi();
@olostan
olostan / routeTransitions.js
Last active August 29, 2015 14:20
routeTransitions for new Angular router
function setupHooks(controller) {
controller.prototype.deactivate = ['$scope',function($scope) {
console.log("deactivating",$scope);
}];
controller.prototype.canActivate = ['routeTransitions','$timeout',function(routeTransitions,$timeout) {
console.log("activating",routeTransitions.sourceElement);
var source = routeTransitions.sourceElement;
if (source) {
routeTransitions.sourceElement = null;
var cloneE = source[0].cloneNode(true);
@olostan
olostan / decorator.dart
Created April 19, 2015 08:29
"sample" Decorator for DaCSS
@Decorator(selector:'[sample]')
class Sample implements AttachAware{
Element _element;
Http _http;
Sample(this._element, this._http);
var sanitizer = const HtmlEscape();
Future<String> getFromDOM(String id) {
var sample = document.querySelector(id);
@olostan
olostan / index.js
Created August 6, 2014 13:43
Bundles support in gulp plugin angular-file-sort
var es = require('event-stream');
var ngDep = require('ng-dependencies');
var toposort = require('toposort');
var ANGULAR_MODULE = 'ng';
module.exports = function angularFilesort (bundleFilter) {
var files = [];
var angmods = {};
var toSort = [];
'use strict';
app
.directive('twfTransferToScope', function () {
return {
restrict: 'E',
link: function (scope, element, attr) {
element.hide();
scope[attr.name] = angular.fromJson(element.text());
}
var fs = require('fs');
var cheerio = require('cheerio');
var Chance = require('chance');
var chance = new Chance();
function getRandomData(type, hint) {
if (type == 'number') {
return (Math.random() * 1000000 | 0) / 100;
} else if (type == 'boolean') {
return Math.random() >= 0.5;