Skip to content

Instantly share code, notes, and snippets.

@vlio20
vlio20 / cancel-previous.ts
Created September 8, 2019 20:02
cancelPrevious
class Data {
@cancelPrevious()
getReportData(data: IReportParams): IReportData {
// some code
}
}
@vlio20
vlio20 / after.ts
Last active September 9, 2019 15:10
utils-decorators
class WidgetProvider {
@after<WidgetProvider, Widget>({
func: () => {
console.log('widget created')
}
})
createWidget(name: string): Widget {
// some code
}
@vlio20
vlio20 / StatusCode.kt
Last active June 19, 2023 23:56
Kotlin Http Status Codes enum
package oogaday.commons.enums
enum class StatusCode(val code: Int) {
Continue(100),
SwitchingProtocols(101),
Processing(102),
OK(200),
Created(201),
Accepted(202),
@vlio20
vlio20 / promise-all-controlled.ts
Created July 11, 2018 05:26
Promise all (not fail fast) with controlled concurrent requests
export interface ISuccessError {
success: boolean;
result?: any;
error?: any;
}
type PromFucn = (...args: any[]) => Promise<any>;
promiseAllConcurrent(promFuncs: PromFucn[],
concurrent: number = 1): Promise<ISuccessError[]> {
@vlio20
vlio20 / memoaize.decorator.ts
Created July 4, 2018 07:04
Typescript memoize decorator
const MEMOIZED_VALUE_KEY = '_memoizedValue';
export function memoize(expirationTimeMs: number = 60000) {
return (target: any, propertyName: string, descriptor: TypedPropertyDescriptor<any>) => {
if (descriptor.value != null) {
const originalMethod = descriptor.value;
const fn: any = function (...args: any[]) {
const key = MEMOIZED_VALUE_KEY + '_' + JSON.stringify(args);
if (!fn[key]) {
@vlio20
vlio20 / debounce.decorator.ts
Created July 4, 2018 06:26
typescript decorator for debounce
export const DEFAULT_DEBOUNCE_MS = 500;
export function debounce(ms: number = DEFAULT_DEBOUNCE_MS): Function {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor): any {
return {
configurable: true,
enumerable: descriptor.enumerable,
get: function (): () => any {
Object.defineProperty(this, propertyKey, {
configurable: true,
@vlio20
vlio20 / batchPromise.ts
Last active July 3, 2018 10:10
batch promises (typescript)
static batchPromise(proms: (() => Promise<any>)[], batchSize: number): Promise<void> {
return this.chunck(proms, batchSize)
.reduce((step: Promise<any>, chunck) => {
return step.then(() => {
return Promise.all(chunck.map(fp => fp()));
});
}, Promise.resolve());
}
private static chunck<T>(array: T[], batchSize = 5): T[][] {
@vlio20
vlio20 / package.json
Created June 23, 2017 18:30
webpack + typescript + react
{
"name": "Oogaday",
"version": "0.0.0",
"main": "index.js",
"author": "Vlad Ioffe",
"license": "MIT",
"scripts": {
"serve": "webpack-dev-server --config=webpack.dev.config.js"
},
"devDependencies": {
@vlio20
vlio20 / refactor-extention.sh
Last active October 26, 2016 20:58
rename extension
for f in $(find `pwd` -name "*.js"); do
cp "$f" "${f%.js}.ts"
done
# Refactoring Directives to 1.5 Components
Below you will find guide on how to refactor your directives to components:
**Step 1 - Rename your files suffix:**
Components should have the suffix `.component.ts` while directives have the `.dir.ts suffix`.
`<file_name>.drv.ts` ==> `<file_name>.component.ts`
Note: all related files should be renamed as well (jade, less, spec etc.).
**Step 2 - Change the module initialization:**
In the relevant module change the initialization from directive to component.