Skip to content

Instantly share code, notes, and snippets.

View bartoszbobin's full-sized avatar

Bartosz Bobin bartoszbobin

View GitHub Profile
@bartoszbobin
bartoszbobin / ICalendarParser.ts
Created April 10, 2018 21:03
Simple ICalendar Parser to JS Objects
View ICalendarParser.ts
/**
* @copyright bartosz.bobin
*/
export class ICalendarParser {
skipNotStandardKeys = true;
parse(text: string) {
const lines = text.replace(/\n /g, '').split(/\n/);
let obj = {vcalendar: undefined};
@bartoszbobin
bartoszbobin / example.js
Last active July 5, 2017 08:26
Javascript - pobranie pliku z backendu na front FF i przekazanie do pobrania, Chrome, Edge, Safari, IE10+
View example.js
var xhr = new XMLHttpRequest();
xhr.open('POST', 'nasz-url', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
// należy wymusić 'arraybuffer'
xhr.responseType = 'arraybuffer';
xhr.onload = onLoad;
xhr.send();
function onLoad() {
if (this.status !== 200) {
@bartoszbobin
bartoszbobin / example.js
Created July 5, 2017 07:54
Javascript - pobranie pliku z backendu na front FF, Chrome, Edge, Safari, IE10+
View example.js
var xhr = new XMLHttpRequest();
xhr.open('POST', 'nasz-url', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
// należy wymusić 'arraybuffer'
xhr.responseType = 'arraybuffer';
xhr.onload = onLoad;
xhr.send();
function onLoad() {
if (this.status === 200) {
@bartoszbobin
bartoszbobin / router-history.ts
Last active September 20, 2016 14:33
UI Router History Service
View router-history.ts
import IStateService = angular.ui.IStateService;
import IRootScopeService = angular.IRootScopeService;
import IState = angular.ui.IState;
class RouterHistory
{
private history : IHistoryEntry[] = [];
public add(stateName : string, stateParams : any) : void
{
@bartoszbobin
bartoszbobin / const-enum.ts
Created September 19, 2016 07:36
TypeScript enum vs const enum
View const-enum.ts
// TypeScript
const enum Beta { X, Y, Z }
const A : Beta = Beta.X;
// JavaScript
var Beta;
(function (Beta) {
Beta[Beta["X"] = 0] = "X";
Beta[Beta["Y"] = 1] = "Y";
View current.ts
'use strict';
// file: route.cfg.ts
class RouteConfig
{
public static $inject = ['$stateProvider'];
public constructor($stateProvider : angular.ui.IStateProvider){
$stateProvider
.state("home", {
@bartoszbobin
bartoszbobin / any.ts
Last active August 29, 2015 14:22
TypeScript - types
View any.ts
enum Color {
RED, GREEN, BLUE
}
class MyClass {}
var myAny: any;
myAny = 'aaa';
myAny = true;
myAny = 0.00;
myAny = undefined;
@bartoszbobin
bartoszbobin / gist:5f4abad19b298ddbc682
Last active August 29, 2015 14:21
TypeScript - Hello World
View gist:5f4abad19b298ddbc682
function test(name: string): any {
if ('bart' === name) {
return 1929;
}
return "Hello " + name;
}
alert(test('Bart'));