Skip to content

Instantly share code, notes, and snippets.

View SevInf's full-sized avatar

Serhii Tatarintsev SevInf

  • Prisma
  • Berlin
  • 18:39 (UTC +02:00)
View GitHub Profile
@SevInf
SevInf / prisma-engine.sh
Last active March 15, 2024 11:21
Script for managing prisma engines versions
# Instructions
# 1. Download this script
# 2. Add `source /path/to/the/script.sh` to your shell profile
# 3. Reload the shell
# 4. Use the command:
# - `prisma-engine use /path/to/checkout/dir` for local checkout
# - `prisma-engine use 12345` for github pull requests
# - `prisma-engine unuse` for resetting all env variables and switching back
# to default engine
@SevInf
SevInf / ColorMath.js
Last active August 27, 2020 13:22
Some color conversion functions
// converts 255, 255, 255 -> #ffffff
export function rgbToHex(r, g, b) {
return '#' + to_hex(r) + to_hex(g) + to_hex(b);
}
function to_hex(color) {
return color.toString(16);
}
// converts 255, 255, 255 -> #ffffff
@SevInf
SevInf / 01-public-fields.js
Created February 24, 2020 14:28
Private fields demo
// thing that exists and we already using
class TreasureChest {
contents = ['golden coin', 'cobweb'];
}
const chest = new TreasureChest();
console.log(chest.contents);
@SevInf
SevInf / proxy.mjs
Last active August 25, 2018 09:54
HMR proxy module
// 1
import { export1, export2 } from './original.mjs?mtime=0';
import { hmrClient } from '/hmrClient.mjs';
// 2
let export1Proxy = export1;
let export2Proxy = export2;
// 3
export {
@SevInf
SevInf / importer2.mjs
Last active August 26, 2018 08:19
URL semantics of ES2015 modules
import { increment } from './counter.mjs';
import { counter } from './counter.mjs?someQueryParameter';
console.log(counter); // prints 1
increment();
console.log(counter); // still prints 1
@SevInf
SevInf / counter.mjs
Created August 25, 2018 09:20
Live bindings demo
export let counter = 1;
export function increment() {
counter++;
}
@SevInf
SevInf / hot-reload.js
Last active August 28, 2018 17:40
Webpack hot reloading example
import { text } from './text.mjs';
document.body.textContent = text;
module.hot && module.hot.accept('./text.mjs', () => {
// here text.mjs is updated and text variable has a new value
document.body.textContent = text;
})
@SevInf
SevInf / codemod.js
Created September 30, 2016 13:20
Codemod to migrate from Q to Bluebird
const replacements = {
'thenResolve': 'thenReturn',
'thenReject': 'thenThrow',
'fcall': 'try'
}
export default function transformer(file, api) {
const j = api.jscodeshift;
const sourceCalls = [];
const f = j(file.source);

Keybase proof

I hereby claim:

  • I am SevInf on github.
  • I am sevinf (https://keybase.io/sevinf) on keybase.
  • I have a public key whose fingerprint is E483 737C 2AE2 4426 C2BC FCFC B89D 6839 8645 615E

To claim this, I am signing this object:

@SevInf
SevInf / gist:09a1e7d913fa46d13265
Last active August 29, 2015 14:21
Promises + generators
async(function*() {
console.log('start');
yield asyncFunction();
var value = yield asyncFunction();
console.log('value', value);
});
function asyncFunction() {
return new Promise((resolve, reject) => {
setTimeout(() => {