Skip to content

Instantly share code, notes, and snippets.

View compressor.js
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 Jul 9, 2017
console.log() for jscore in swift
View console_log.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)!)
View keybindings.json
[
{
"key": "ctrl+1",
"command": "workbench.action.focusFirstEditorGroup"
},
{
"key": "ctrl+2",
"command": "workbench.action.focusSecondEditorGroup"
},
{
View sql_alchemy_boilerplate.py
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()
View prom.js
async function foo (bar) {
return bar + ' baz'
}
foo('test').then(console.log)
View defaultDataReducer.js
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 Jan 14, 2017
If you like atom's OneDark syntax theme but think there is too much red in your JavaScript
View styles.less
.theme-one-dark-ui {
.syntax--variable {
color: inherit;
}
.syntax--this {
color: #e06c75;
}
}
@szastupov
szastupov / modern.js
Created Dec 19, 2016
tfw javascript looks like haskell
View modern.js
const updater = (data, onUpdate) => (field) => (value) => {
onUpdate({
...data,
[field]: value
})
}
View keybase.md

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 Jul 6, 2016
websocket/long polling event bus
View events.py
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