Skip to content

Instantly share code, notes, and snippets.

@jakobz
jakobz / test-gc
Last active March 28, 2025 15:32
Test if function gets garbage-collected
// To track the ref
window.wm = new WeakMap();
function init() {
// Make something memory-expensive. Small objects might not get's GCer
const huge = [];
for(var i = 0; i < 100500; i++) {
huge[i] = i;
}
@jakobz
jakobz / gist:047b52bccc7d19bb24904fe5e981aeef
Last active November 9, 2019 22:07
Typed Redux wrapper
import { Reducer } from "redux";
import { Dispatch } from "react-redux";
export type ReducerCur<TState, TPayload = any> = (payloyoad: TPayload) => (state: TState) => TState;
export type ActionCreator<TPayload> = (payload: TPayload) => ({ type: string } & TPayload);
type GetActionCreator<TState, T> = T extends ReducerCur<TState, infer TPayload> ? ActionCreator<TPayload> : void;
export type ActionCreatorsSet<TState, T> = { [TName in keyof T]: GetActionCreator<TState, T[TName]> };
export interface Bundle<TState, TReducersSet> {
import { Reducer } from "redux";
import { Dispatch } from "react-redux";
export type ReducerCur<TState, TPayload = any> = (payloyoad: TPayload) => (state: TState) => TState;
export type ActionCreator<TPayload> = (payload: TPayload) => ({ type: string } & TPayload);
type GetActionCreator<TState, T> = T extends ReducerCur<TState, infer TPayload> ? ActionCreator<TPayload> : void;
export type ActionCreatorsSet<TState, T> = { [TName in keyof T]: GetActionCreator<TState, T[TName]> };
export interface Bundle<TState, TReducersSet> {
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using Epam.Api.Eco;
using Location = Edu.AppTools.Data.Models.Location;
using Room = Edu.AppTools.Data.Models.Room;
namespace Edu.AppTools.Service.Locations.Rooms
<!DOCTYPE HTML>
<style>
/*!
* Font Awesome 4.7.0 by @davegandy - http://fontawesome.io - @fontawesome
* License - http://fontawesome.io/license (Font: SIL OFL 1.1, CSS: MIT License)
*/@font-face{font-family:FontAwesome;src:url(/static/media/fontawesome-webfont.674f50d2.eot);src:url(/static/media/fontawesome-webfont.674f50d2.eot?#iefix&v=4.7.0) format("embedded-opentype"),url(/static/media/fontawesome-webfont.af7ae505.woff2) format("woff2"),url(/static/media/fontawesome-webfont.fee66e71.woff) format("woff"),url(/static/media/fontawesome-webfont.b06871f2.ttf) format("truetype"),url(/static/media/fontawesome-webfont.912ec66d.svg#fontawesomeregular) format("svg");font-weight:400;font-style:normal}.fa{display:inline-block;font:normal normal normal 14px/1 FontAwesome;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.fa-lg{font-size:1.33333333em;line-height:.75em;vertical-align:-15%}.fa-2x{font-size:2em}.fa-3x{font-size:3em}.fa-4x{font-size:4em}.fa-5x{f
@jakobz
jakobz / proplens.ts
Created March 30, 2017 09:14
Simple Lenses for React props
interface LensProps<T> {
value: T,
onValueChange(newValue: T): void;
}
function propLens<TParent extends object, Name extends keyof TParent>(parent: LensProps<TParent>, name: Name): LensProps<TParent[Name]> {
return {
value: parent.value[name],
onValueChange: (newValue) => parent.onValueChange({ ...parent.value as any, [name as any]: newValue })
}
@jakobz
jakobz / index.ts
Created March 28, 2017 22:16
Tiny Typed Redux-like state manager in typescript
// Redux mini
type Reducer<TPayload, TState> = (params: TPayload) => (state: TState) => TState;
type Action<TPayload> = { name: string, payload: TPayload };
type ActionFactory<TPayload> = (payload: TPayload) => Action<TPayload>;
type ActionDispatcher<TPayload> = (payload: TPayload) => void;
type ReducersSet<TActions, TState> = { [P in keyof TActions]: Reducer<TActions[P], TState> }
type ActionFactorySet<TActions> = { [TActionName in keyof TActions]: ActionFactory<TActions[TActionName]> }
type ActionDispatcherSet<TActions> = { [TActionName in keyof TActions]: ActionDispatcher<TActions[TActionName]> }
javascript:(function()%7Bdocument.querySelectorAll('.nested-data.activities-container .table-right-part').forEach(part %3D> %7Blet leftDays %3D part.querySelectorAll('.table-week.first-week .table-activity-cell.cell input')%3Blet rightDays %3D part.querySelectorAll('.table-week.last-week .table-activity-cell.cell input')%3BrightDays.forEach((rightDay%2C idx) %3D> %7BrightDay.value %3D leftDays%5Bidx%5D.value%3Bvar event %3D new Event('blur')%3BrightDay.dispatchEvent(event)%3B%7D)%7D)%7D)()
class ClassA {
public ClassB B { get; set; }
}
class ClassB {
public ClassA A { get; set; }
}
ClassA a = new ClassA();
ClassB b = new ClassB();
JavaScript
0. Нравится ли тебе javascript как язык программирования?
Сам факт того что JS нравится/не нравится - весьма показателен, т.к. отношение к нему меняется у всех примерно одинаково в процессе погружения - от яркой неприязни, к пониманию и легкой эйфории, и потом уже к взвешенному отношению.
1. На замыкания и this
HTML:
<div id='my-div'>My Div</div>