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
/**
* @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+
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+
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
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
// 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";
'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
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
function test(name: string): any {
if ('bart' === name) {
return 1929;
}
return "Hello " + name;
}
alert(test('Bart'));