Skip to content

Instantly share code, notes, and snippets.

Avatar

Kirill Sukhomlin kirilloid

View GitHub Profile
View languages-stats.txt
el-GR: 9705
fr-FR: 9684
it-IT: 9394
de-DE: 9391
nl-NL: 9174
es-CL: 9076
ro-RO: 9073
ms-MY: 8998
id-ID: 8993
hu-HU: 8983
@kirilloid
kirilloid / cloneViaPostMessage.js
Last active Jan 7, 2018
deep clone test suite
View cloneViaPostMessage.js
var handlers = {};
self.addEventListener('message', function (event) {
if (event.origin !== location.origin) return;
var key = event.data.key;
var value = event.data.value;
if (!handlers[key]) return;
handlers[key](value);
delete handlers[key];
});
View hindi.java
import java.util.Locale;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class HelloWorld
{
public static void main(String[] args)
{
Locale hiDflt = Locale.forLanguageTag("hi-IN");
View xml2json.js
function pascalize(string) {
return string.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
}
function normalize(value) {
if (/^(null|true|false)$/.test(value)) {
return JSON.parse(value);
}
return value;
}
View assign.js
function assingImmutable(obj, toAdd) {
if (!_.isObjectLike(toAdd)) {
return toAdd;
}
key = _.first(path);
if (_.isArray(obj)) {
copy = _.slice(obj);
toAdd.forEach(function (value, idx) {
copy[idx] = assingImmutable(obj[idx], value);
});
View type.js
function getType (value) {
let type = typeof value;
if (type === 'object') {
return value ? Object.prototype.toString.call(value).slice(8, -1) : 'null';
}
return type;
}
[NaN, 0, 1, Infinity, // numbers
null, undefined, false, 'str', // other primitives
View walk-tree.js
/**
* @param {Node} node
* @template T
*/
function Node (key, left, right) {
/** @property {T} key */
this.key = key;
if (left) left.parent = this;
if (right) right.parent = this;
/** @property {Node<T>} left */
View factory.js
class Shape {
constructor (type, ...args) {
super();
switch (type) {
case 'rect':
return new Rectangle(...args);
case 'circle':
return new Circle(...args);
}
}
View main.js
(function decompress (s) {
var i, c, out = "", len, offset;
for (i = 0; i < s.length; i++) {
c = s.charCodeAt(i);
if (c >= 256 && c <= 288) {
len = c - 256;
offset = s.charCodeAt(++i);
out += out.substr(-offset, len);
} else {
out += s.charAt(i);
View main.js
(function (n, m) {
if (typeof m === 'undefined') { m = 1; }
if (typeof n === 'undefined') { throw new TypeError("Provide at least first number"); }
function randSort () {
return Math.random() * 2 - 1;
}
function getArr(n) {
var a = [];
for (var i = 1; i <= n; i++) { a.push(i); }