Skip to content

Instantly share code, notes, and snippets.

View Ginden's full-sized avatar

Michał Wadas Ginden

  • Future Mind
  • Warsaw, Poland
View GitHub Profile
var max = 1000;
var min = 1;
var interval = 10;
var array = new Array(5000).join().split('').map(()=>Math.random() > 0.1 ? (Math.random()*(max-min)+min) : 'string');
var strings = array.filter(el=>typeof el === 'string');
result = array.filter(el=>typeof el === 'number').forEach(function(el) {
var place = (el/interval)|0;
(this[place] = this[place] || []).push(el);
}, result);
result.push(strings);
function getInt31() {
return Math.floor(Math.random()*2147483648).toString();
}
function getInt32() {
return Math.floor((0.5-Math.random())*4294967296).toString();
}
function getBigInt() {
// Constant deoptimizations, why?
@Ginden
Ginden / gist:754c93c4850f62f2629e
Created May 13, 2015 15:19
MS SQL Server - get all indexes with columns
WITH [objects] as (
SELECT
B.name as [schema_name],
A.name,
A.[object_id] as id,
A.type_desc as [object_type]
FROM sys.objects A
INNER JOIN sys.schemas B ON A.schema_id = B.schema_id
WHERE A.type_desc IN ('USER_TABLE' /*, 'VIEW'*/)
),
var numbers = Array(500*1000).join('a').split('').map(function(){
return (1-Math.random())*Math.pow(2,200);
});
(function bench(){
for(var i = 0; i < numbers.length; i++) {
~~numbers[i];
}
})();
var toArray1 = function toArray1(arr){
return [].slice.call(arr);
};
var toArray2 = function toArray2(args) {
var len = args.length,
arr = new Array(len), i;
for (i = 0; i < len; i += 1) {
arr[i] = args[i];
BEGIN TRANSACTION LENIWY_YAHOO;
CREATE TABLE #A(PK INT IDENTITY(1,1) PRIMARY KEY, Ignore INT);
INSERT INTO #A(Ignore)
SELECT CHECKSUM(NEWID()) FROM sys.objects;
ALTER TABLE #A ADD [nowy_timestamp] timestamp NOT NULL;
SELECT * FROM #A;
WITH Wages(Euro, CountryName) AS (
SELECT 357,"Albania"UNION ALL
SELECT 2230,"Andorra"UNION ALL
SELECT 315,"Armenia"UNION ALL
SELECT 2124,"Austria"UNION ALL
SELECT 224,"Azerbaijan"UNION ALL
SELECT 249,"Belarus"UNION ALL
SELECT 2091,"Belgium"UNION ALL
SELECT 425,"Bosnia and Herzegovina"UNION ALL
SELECT 376,"Bulgaria"UNION ALL
@Ginden
Ginden / analysis.sql
Last active March 14, 2016 12:31
Salaries PPP
CREATE TABLE Countries(
Country VARCHAR(30) PRIMARY KEY,
[GDP_$] INT,
[GDP PPP $] INT,
[Salary €] INT
);
INSERT INTO Countries
SELECT 'Luxembourg', 111716, 91047, 3149 UNION ALL
SELECT 'Norway', 97013, 64893, 3212 UNION ALL
[
{
"country": "Afghanistan",
"publicHealthExpenditures": 2.9
},
{
"country": "Albania",
"publicHealthExpenditures": 2.9
},
{
const BACKING_MAP = Symbol('Backing map for CustomEqualitySet');
const HASH_FUNCTION = Symbol('Hash function for CustomEqualitySet');
export default class CustomEqualitySet extends Set {
constructor(iterable=[], hashFunction=val=>val) {
super();
this[BACKING_MAP] = new Map();
this[HASH_FUNCTION] = hashFunction;
for(const el of iterable) {
this.add(el);