Skip to content

Instantly share code, notes, and snippets.

function compress(signal, threshold, ratio, makeup) {
return signal.map(x => {
let amp = Math.abs(x)
let sign = Math.sign(x)
if (amp > threshold) {
amp = (amp - threshold) * ratio + threshold
}
return sign * (amp * makeup)
})
}
@szastupov
szastupov / console_log.swift
Created July 9, 2017 09:08
console.log() for jscore in swift
context.evaluateScript("var console = { log: function(...args) { _consoleLog(args.join(' ')) } }")
let consoleLog: @convention(block) (String) -> Void = { message in
print("console.log: " + message)
}
context.setObject(unsafeBitCast(consoleLog, to: AnyObject.self), forKeyedSubscript: "_consoleLog" as (NSCopying & NSObjectProtocol)!)
[
{
"key": "ctrl+1",
"command": "workbench.action.focusFirstEditorGroup"
},
{
"key": "ctrl+2",
"command": "workbench.action.focusSecondEditorGroup"
},
{
import sqlalchemy as sa
from sqlalchemy.ext.declarative import as_declarative, declared_attr
from sqlalchemy.orm import relationship, sessionmaker
engine = sa.create_engine('sqlite://')
Session = sessionmaker(bind=engine)
@as_declarative()
@szastupov
szastupov / prom.js
Last active February 17, 2017 19:30
async function foo (bar) {
return bar + ' baz'
}
foo('test').then(console.log)
import { deleteAt, updateObjectAt, swap } from '../../lib/farr'
export function defaultDataReducer(name, initialData = null) {
const initialState = {
[name]: initialData,
isFetching: true,
isFetched: false,
isRequested: false
}
@szastupov
szastupov / styles.less
Last active January 14, 2017 20:45
If you like atom's OneDark syntax theme but think there is too much red in your JavaScript
.theme-one-dark-ui {
.syntax--variable {
color: inherit;
}
.syntax--this {
color: #e06c75;
}
}
@szastupov
szastupov / modern.js
Created December 19, 2016 17:00
tfw javascript looks like haskell
const updater = (data, onUpdate) => (field) => (value) => {
onUpdate({
...data,
[field]: value
})
}

Keybase proof

I hereby claim:

  • I am szastupov on github.
  • I am szastupov (https://keybase.io/szastupov) on keybase.
  • I have a public key whose fingerprint is B85B B0D5 5772 7618 6F6F 4DAE 015D 9FBF 37D4 D119

To claim this, I am signing this object:

@szastupov
szastupov / events.py
Created July 6, 2016 13:47
websocket/long polling event bus
import logging
from tornado.websocket import WebSocketHandler
from tornado.web import asynchronous
from tornado.ioloop import PeriodicCallback
from helpers.event_bus import bus
from helpers.api import CommonHandlerMixin
from helpers.auth import http_token
from functools import partial
from . import routes