Skip to content

Instantly share code, notes, and snippets.

@quant61
quant61 / 0
Last active February 9, 2018 19:42
PublicGist0
some esoteric ES6 functions
var getDiagonalMatrix = N=>Array(N).fill(0).map((x,i)=>Array(N).fill(i).map((x,j)=>i==j?1:0));
var getNDArray = (N, x)=>N.length?(Array(N[0]).fill(0).map(()=>arr(N.slice(1),x))):x;
var toBase = (x,n,r=[])=>x ? toBase(Math.trunc(x/n), n, [ x%n, ...r]):r;
@quant61
quant61 / Javascript_toNumber.md
Last active January 10, 2023 11:58
conversion to number in javascript

Some notes about conversion to number in javascript

javascript has lots of methods to convert any value to number

  • all methods could be divided into 2 groups: string and native methods
    • String methods are parseInt and parseFloat
    • Native mathods are Number and Math methods

all native methods behave the same way, sometimes with additional transform

@quant61
quant61 / mixValue.js
Last active February 23, 2017 08:32
getting javascript value of random type
// special Javascript values
const specials = [null, true, false, undefined, NaN, 1/0, -1/0, -0];
function getMixValue(){
return randIndex([
randSpecial,
randInt,
randFloat,
randStr,
@quant61
quant61 / sql search notes.sql
Created May 7, 2017 18:05
notes on search in mysql
/*
* searching some values in mysql is not as easy as you think
* some search may not work way you think
* for example, it's virtually impossible to search NULL values
* without `IS NULL`
*
* you can test this queries using your local mysql or online services like sqlfiddle
*
*/
@quant61
quant61 / notes-1.md
Last active February 15, 2020 21:02
public random notes

I have lots of notes in my local files and also I plan to move them to gists.

// TODO: improve&refactor

// symfony convert request body to array:
@quant61
quant61 / vnode.md
Last active January 20, 2018 13:34

idea about variable inode(vnode)

it's like php's zval, but more compact and supports many types as primitives

vnode takes 16 bytes exactly 4 bytes is header 12 bytes - value

vnodes could be useful for big arrays of mixed values

@quant61
quant61 / SafeNullClass.php
Created August 26, 2017 17:17
SafeNullClass.php
<?php
/**
* Created by PhpStorm.
* User: kwant
* Date: 26.08.17
* Time: 19:50
*
* attempt to create NullObject in php
* this object does nothing
@quant61
quant61 / extensions.md
Last active February 3, 2018 16:01
msgpack extensions

some proposals of msgpack extensions

some general notes

msgpack ext value has following structure:

+--------+--------+--------+========+
|  extX  |  SIZE  |  type  |  data  |
+--------+--------+--------+========+
@quant61
quant61 / functions.go
Last active March 4, 2021 17:16
functions
// protects from directory traversal
func safeJoin(baseDir, path string) string{
return filepath.Join(baseDir, filepath.Join("/", path))
}
func getSyscallArg(v interface{}) uintptr {
@quant61
quant61 / gist:4dcf7cc23ad54c877b9b0556f7d7a084
Created January 28, 2018 13:58
эксперимент со слепой печатью
*скорее всего, эксперимент проводился в 2016, а текст только сейчас залил.
слепая печать
для эксперимента печатал непрерывно и с закрытыми глазами в течении 5 минут.
5 минут
1017 символов(всего)
974 не считая ентеров