Skip to content

Instantly share code, notes, and snippets.

View ahiipsa's full-sized avatar
🐙

Sergei Karasev ahiipsa

🐙
  • Armenia, Yerevan
  • 20:38 (UTC +04:00)
View GitHub Profile
@ahiipsa
ahiipsa / HELPERS.md
Last active September 23, 2020 15:49

TypeScript Fix Object.keys

export function keys<O>(o: O) {
  return Object.keys(o) as (keyof O)[];
}

Add your SSH public key to the remote server

@ahiipsa
ahiipsa / randomEnum.ts
Created November 26, 2019 14:21
TypeScript Random Enum
const randomEnum = <T>(arr: readonly T[]) => {
type ReturnType = typeof arr[number];
return (): ReturnType => {
const index = Math.floor(Math.random() * arr.length);
return arr[index];
}
};
@ahiipsa
ahiipsa / randomEnum.ts
Created November 26, 2019 14:21
TypeScript Random Enum
const randomEnum = <T>(arr: readonly T[]) => {
type ReturnType = typeof arr[number];
return (): ReturnType => {
const index = Math.floor(Math.random() * arr.length);
return arr[index];
}
};
@ahiipsa
ahiipsa / dom_exception_18.js
Last active June 14, 2016 18:51
Test case: Error: SecurityError: DOM Exception 18
// test case
var currentUrl = window.location.toString();
for (var i = 0; i < 105; i++) {
window.history.replaceState({location: currentUrl}, "", currentUrl);
}
@ahiipsa
ahiipsa / sequelize_patch.md
Last active August 29, 2015 13:58
How to find a records with two or more relationships.

I have the following JS code:

db.models
    .Vobject
    .findAndCountAll({
    where: [{type: 1 }],
    include: [{model: db.models.Tag, where: {name: ['iron', 'tefal']}}],
    limit: 10
})
@ahiipsa
ahiipsa / sequelize.js
Last active August 29, 2015 13:56
Sequelize note
// create field but not create fk index
User.hasMany(Media);
Media.belongsTo(User);
Media.hasOne(User);
User.belongsTo(Media);
// foreignKeyConstraint create fk index
User.hasMany(Media, {as: 'Media', foreignKeyConstraint: true});
Media.belongsTo(User);