Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@gnaeus
gnaeus / example.tsx
Last active September 11, 2019 15:30
class FirstStore extends Injectable {}
class SecondStore extends Injectable {
firstStore = this.getInstance(FirstStore);
}
class FirstComponent extends ConnectedComponent {
firstStore = this.getInstance(FirstStore);
secondStore = this.getInstance(SecondStore);
@gnaeus
gnaeus / Cookies.md
Last active September 13, 2017 07:34

Cookies: AUTH=payload.userId.rememberMe.timestamp; HttpOnly; XSRF-TOKEN=signarure;

AUTH – HttpOnly Session Cookie, выдается при логине, удаляется при выходе.

  • payload – данные пользователя, получаемые из БД на основе userId,
  • userId – идентификатор пользователя,
  • rememberMe – флаг "запомнить меня",
  • timestamp – время выпуска данной Cookie.

XSRF-TOKEN – Session Cookie, выдается, обновляется и удаляется строго вместе с AUTH Cookie.

var computerInfo = new Microsoft.VisualBasic.Devices.ComputerInfo();
ulong occupied = computerInfo.TotalPhysicalMemory - computerInfo.AvailablePhysicalMemory;
float occupiedPercentage = (float)occupied / computerInfo.TotalPhysicalMemory;
@gnaeus
gnaeus / BastardInjection.cs
Last active May 29, 2017 12:41
[C#] Helpers for Bastard Injection pattern
using System;
using System.Threading;
namespace BastardInjection
{
public abstract class Transient<T> where T : new()
{
public static T Instance => new T();
}
function usersReducer(state, action) {
switch (action.type) {
case CHANGE_NAME:
const { id, name } = action.payload;
return {
byId: protoMerge(state.byId, {
[id]: {
...state.byId[id],
name: name,
}
@gnaeus
gnaeus / protoMerge.js
Created April 26, 2017 13:05
[JS] Speedup Redux normalized state 'byId' object transformation
function protoMerge(source, changes, mergeThreshold = 100) {
let result;
const proto = Object.getPrototypeOf(source);
if (proto === Object.prototype || proto == null) {
// если source создан как object literal - то просто наследуемся от него
result = Object.create(source);
} else {
const sourceKeys = Object.keys(source);
const sourceLength = sourceKeys.length;
function usersReducer(state, action) {
switch (action.type) {
case CHANGE_NAME:
const { id, name } = action.payload;
return {
byId: {
...state.byId,
[id]: {
...state.byId[id],
name: name,
users: {
byId: {
"user1": {
id: "user1",
name: "John",
},
"user2": { ... },
...
},
allIds: [ "user1", "user2", ... ],