Skip to content

Instantly share code, notes, and snippets.

View vladimir-ivanov's full-sized avatar

vladimir ivanov vladimir-ivanov

View GitHub Profile
@vladimir-ivanov
vladimir-ivanov / observable-request-service-spec.ts
Last active January 22, 2017 22:54
example of angular2 spec with MockBackend for the Http object - angular2 test
///<reference path="../../../typings/angularjs/angular-mocks.d.ts"/>
import {ObservableRequestService} from '../../../src/core/observable-request-service.ts';
import {
Http,
ConnectionBackend,
BaseRequestOptions,
MockBackend,
ResponseOptions,
Response
} from 'angular2/http';
@vladimir-ivanov
vladimir-ivanov / observable-request-service.ts
Last active February 19, 2016 08:58
observable wrapper for angular2 Http, using jQuery as a temporary solution to allow withCredentials property on xhr object
/// <reference path='../../typings/angularjs/angular.d.ts' />
//TODO - a temp fix is using jquery ajax until angular2/http adds support for withCredentials on their xhr objects
import {Http, Headers} from 'angular2/http';
import {Injectable, Observable} from 'angular2/core';
@Injectable()
export class ObservableRequestService {
constructor(private http:Http) {
}
@vladimir-ivanov
vladimir-ivanov / dispatcher.ts
Created November 20, 2015 13:27
event emitter (dispatcher) for anuglar2 - depends on EventEmitter
import {EventEmitter} from 'angular2/angular2';
class Dispatcher {
subjects = {};
constructor() {
}
emit(topic, data = null) {
this.getInstance(topic).next(data);
//could also be a non recursive function etc
function factorial(n) {
return (n < 2) ? 1 : factorial(n-1) * n;
}
function getElementAtPosition(n, k) {
return factorial(n) / (factorial(k) / factorial(n-k));
}
function pascalRow(n) {
@vladimir-ivanov
vladimir-ivanov / config.js
Last active November 29, 2015 21:17
systemjs config for typescript
System.transpiler = 'typescript';
System.meta['typescript'] = {format: 'global', exports: 'ts'};
System.paths = {
'*': '*.ts',
'typescript': 'node_modules/typescript/lib/typescript.js'
};
System.import('/src/main.ts');
@vladimir-ivanov
vladimir-ivanov / mercator map on canvas
Created July 8, 2015 10:56
mercator map on canvas depends on datamaps
var width = 960,
height = 500;
var clip = d3.geo.clipExtent()
.extent([
[0, 0],
[width, height]
]);
var canvas = d3.select("body").append("canvas")
@vladimir-ivanov
vladimir-ivanov / gist:df45ef30db82da69d7db
Created January 27, 2015 20:36
force layout with lasso js
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.4.6"></script>
<link href='http://mbostock.github.com/d3/ex/force.css' rel='stylesheet' type='text/css'/>
<script src='http://mbostock.github.com/d3/d3.layout.js?2.4.6' type='text/javascript'></script>
<script src='http://mbostock.github.com/d3/d3.geom.js?2.4.6' type='text/javascript'></script>
<script src="http://axc.net/code_libraries/lasso/lasso.min.js"></script>
<style>
@vladimir-ivanov
vladimir-ivanov / RouteProviderRegex.js
Created July 17, 2013 15:47
Adding support for Regex in $routeProvider for angularjs. Makes the matches available in $routeParams Need to add App.provider('$route', App.Lib.RouteProviderRegex); And the actual $routeProvider.when(/someRegexHere/);
/**
* @ngdoc object
* @name ng.$routeProvider
* @function
*
* @example
* add this to the App
* App.provider('$route', App.Lib.RouteProviderRegex);
*
* And
@vladimir-ivanov
vladimir-ivanov / Tooltip.js
Created June 18, 2013 11:28
AngularJs Tooltip with html content directive
/*jshint bitwise:true, camelcase:true, curly:true, eqeqeq:true, forin:true, latedef:true, newcap:true, noarg:true,
noempty:true, nonew:true, undef:true, unused:true, strict:true, browser:true, camelcase:false */
/*globals
$: false
*/
/*exported
ToolTipDirective
*/
@vladimir-ivanov
vladimir-ivanov / Sortable.js
Created June 18, 2013 11:28
AngularJs Sortable directive
/*jshint bitwise:true, camelcase:true, curly:true, eqeqeq:true, forin:true, latedef:true, newcap:true, noarg:true,
noempty:true, nonew:true, undef:true, unused:true, strict:true, browser:true, camelcase:false */
/*globals
$: false
*/
/*exported
SortableDirective
*/