Skip to content

Instantly share code, notes, and snippets.

View SPY's full-sized avatar

Ilya Rezvov SPY

  • Google
  • Denver, USA
View GitHub Profile
@SPY
SPY / hex-float-parser.js
Last active April 20, 2021 02:25
JS parser for Float Hex notation
function floatToWord(f) {
let b = new ArrayBuffer(4)
let iView = new Uint32Array(b)
let fView = new Float32Array(b)
fView[0] = f
return iView[0]
}
function wordToFloat(w) {
let b = new ArrayBuffer(4)
-- | Names are hierarchies of strings, describing scope (so no danger of
-- duplicate names, but need to be careful on lookup).
data Name = UN !T.Text -- ^ User-provided name
| NS !Name [T.Text] -- ^ Root, namespaces
| MN !Int !T.Text -- ^ Machine chosen names
| SN !SpecialName -- ^ Decorated function names
| SymRef Int -- ^ Reference to IBC file symbol table (used during serialisation)
instance Show Name where
function whereToEat(except) {
const ALL_OPTIONS = [
{ name: 'Китайцы', days: [2, 3, 4, 5] },
{ name: 'Итальянцы', days: [2, 3, 4, 5] },
{ name: 'Греки', days: [1, 2, 3, 4, 5] },
{ name: 'Суши', days: [2, 3, 4, 5] },
{ name: 'Вьетнамцы', days: [2, 4, 5] },
{ name: 'Кабул', days: [5] },
{ name: 'Джерси Джо', days: [2, 3, 4, 5] },
{ name: 'Бургеры', days: [2, 3, 4, 5] },
export interface FlexChild {
flexBase: number,
flexGrow: number,
flexShrink: number,
maxWidth?: number,
minWidth?: number
}
function sumBy<T>(items: T[], getter: (item: T) => number): number {
return items.reduce((sum, item) => sum + getter(item), 0)
@SPY
SPY / typescriptreact.json
Last active October 3, 2016 09:42
Code snippet for fast react class scafolding
{
"New React Class for CSP": {
"prefix": "new-react-csp",
"body": [
"import * as React from 'react'",
"import * as bem from 'csp-react/src/bem'",
"",
"export interface ${Component}Props extends React.Props<${Component}> {",
"\tclassName?: string | { toString(): string }",
"}",
@SPY
SPY / bwt.ts
Last active July 10, 2016 12:14
TypeScript implementation of Burrows–Wheeler transform. It is more effective than naive implementation and requires O(n) additional memory for direct and inverse transformation.
const enum Order {
LT = -1,
EQ = 0,
GT = 1
}
interface BWTransformed {
data: string,
start: number,
eof: number
@SPY
SPY / slice_to_i32.rs
Created April 18, 2016 09:11
Convert Rust u8 slice to i32
fn slice_to_i32_be(data: &[u8]) -> i32 {
assert!(data.len() >= 4);
let first = data[0];
let sign = if first & 0x80 != 0 { -1 } else { 1 };
sign * (
(((first & 0x7F) as i32) << 24) +
((data[1] as i32) << 16) +
((data[2] as i32) << 8 ) +
( data[3] as i32 )
)
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var ExtendedDefinePlugin = require('extended-define-webpack-plugin')
var path = require('path')
module.exports = {
entry: './src/index.tsx',
resolve: {
alias: {
src: path.join(__dirname, 'src'),
store: path.join(__dirname, 'src', 'store'),
exports.up = function(db) {
return new Promise(function (resolve, reject) {
db.dropTable('companies')
}).then(
db.createTable('companies', {
company_id: { type: 'bigserial', primaryKey: true },
company_name: { type: 'string', unique: true },
domain: { type: 'string', unique: true },
owner: 'bigint'
})
import * as React from 'react'
interface Point {
x: number,
y: number
}
interface DraggableState {
dragStartPoint?: Point
}