Skip to content

Instantly share code, notes, and snippets.

View kbkk's full-sized avatar

Jakub Kisielewski kbkk

View GitHub Profile
@kbkk
kbkk / deferred.ts
Created April 15, 2020 13:02
TypeScript Deferred Promise
function deferPromise<T>(): {
resolve: ( value?: ( PromiseLike<T> | T ) ) => void;
reject: ( reason?: unknown ) => void;
promise: Promise<T>;
} {
let resolve: ( value?: T | PromiseLike<T> ) => void;
let reject: ( reason?: unknown ) => void;
// eslint-disable-next-line promise/param-names
const promise: Promise<T> = new Promise( ( promiseResolve, promiseReject ) => {
@kbkk
kbkk / bump-major.js
Created March 12, 2020 13:52
Bump package.json major version
const fs = require( 'fs' );
const semver = require( 'semver' );
const cwd = process.cwd();
const packageJsonPath = cwd + '/package.json';
const content = fs.readFileSync( packageJsonPath, 'utf-8' );
const [ fullMatch, currentVersion ] = content.match( /"version": "(.*)?"/ ) || [];
@kbkk
kbkk / validator.js
Last active February 28, 2020 13:57
Validators with TypeScript
type GuardedType<T> = T extends (x: any) => x is (infer T) ? T : never;
interface Validator<T> {
isValid(value: any): value is any;
notRequired(): NotRequiredValidator<T>;
required(): RequiredValidator<T>;
nullable(): NullableValidator<T>;
#include "stdafx.h"
#include "zadanie3.h"
#include <vector>
#include <fstream>
#include <iostream>
#include <string>
std::vector<int> przemnoz(const std::vector<int> &idVec)
{
std::vector<int> resultVec;
@kbkk
kbkk / 6.py
Last active December 6, 2017 16:57
banks = [int(x) for x in open('data.txt', 'r').read().split("\t")]
memory_history = {}
counter = 0
since_last_occurence = 0
def redistribute():
bank = banks.index(max(banks))
bank_size = banks[bank]
banks[bank] = 0
process((params, emit) => {
const zip = new JSZip();
const countryBlocksZip = 'GeoLite2-Country-CSV_20171003/GeoLite2-Country-Blocks-IPv4.csv';
const countryLocationsZip = 'GeoLite2-Country-CSV_20171003/GeoLite2-Country-Locations-en.csv';
emit(0);
const parseFile = (zipFile, emitPre, emitPost) => {
return zip
@kbkk
kbkk / ComObjectMapper.cs
Created July 16, 2017 19:33
COM Interop Object Mapper for AutoMapper 6
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Linq.Expressions;
using AutoMapper.Execution;
using AutoMapper.Internal;
using System.Reflection;
@kbkk
kbkk / pimple.json
Created November 1, 2015 22:15
Bolt pimple.json dump
[
{
"name": "logger",
"type": "null",
"value": ""
},
{
"name": "routes",
"type": "class",
"value": "Symfony\\Component\\Routing\\RouteCollection"