This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ Number.prototype.divmod = function (n) { return [Math.floor(this / n), this % n]; } | |
=> function (n) { | |
return [Math.floor(this / n), this % n]; | |
} | |
$ typeof 1 | |
=> "number" | |
$ typeof 1.0 | |
=> "number" | |
$ 1.0.divmod | |
=> embedded:16 function (n) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
"use strict"; | |
function time_to_seconds(time) { | |
var s = time.attributes.datetime.value.split(":"); | |
return parseInt(s[0] * 3600, 10) + parseInt(s[1] * 60, 10) + parseInt(s[2], 10); | |
} | |
var highlighter = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
all: (f)-> | |
for e in this | |
return false unless f(e) | |
true | |
any: (f)-> | |
for e in this | |
return true if f(e) | |
false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Number::log = (base)-> Math.log(this)/Math.log(base) | |
Number::pow = (exp)-> Math.pow(this, exp) | |
Number::ceil = -> Math.ceil(this) | |
Number::floor = -> Math.floor(this) | |
Array::first = -> this[0] | |
Array::last = -> this[@length-1] | |
Array::min = -> @sort().first() | |
Array::max = -> @sort().last() | |
Array::minmax = -> sorted = @sort(); [sorted.first(), sorted.last()] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
// Use of this source code is governed by a BSD-style license that can be | |
// found in the LICENSE file. | |
chrome.commands.onCommand.addListener(function(command) { | |
console.log('onCommand event received for message: ', command); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# examples | |
spec = { | |
"apiKey" => String, | |
"language" => ["en", "ru"], | |
"clientData" => { | |
"userName" => String, | |
"userCity" => String, | |
"userPhoneNo" => String, | |
"userPassword" => String |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def some_combination_of_the_numbers_adds_to_the_biggest_number(arr) | |
arr = arr.sort | |
biggest = arr.pop | |
(2..arr.size).each do |perm_size| | |
arr.permutation(perm_size).each do |nums| | |
sum = nums.reduce(:+) | |
return true if sum == biggest | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lstat("/usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 | |
lstat("/usr/lib", {st_mode=S_IFDIR|0755, st_size=200704, ...}) = 0 | |
lstat("/usr/lib/ruby", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 | |
lstat("/usr/lib/ruby/gems", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 | |
lstat("/usr/lib/ruby/gems/2.1.0", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 | |
lstat("/usr/lib/ruby/gems/2.1.0/gems", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 | |
lstat("/usr/lib/ruby/gems/2.1.0/gems/slop-3.6.0", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 | |
lstat("/usr/lib/ruby/gems/2.1.0/gems/slop-3.6.0/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 | |
lstat("/usr/lib/ruby/gems/2.1.0/gems/slop-3.6.0/lib/slop.rb", {st_mode=S_IFREG|0644, st_size=19793, ...}) = 0 | |
open("/usr/lib/ruby/gems/2.1.0/gems/slop-3.6.0/lib/slop/option.rb", O_RDONLY|O_CLOEXEC) = 7 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from itertools import islice | |
from time import time | |
def time_generator(func, n=500000): | |
generator = func() | |
start = time() | |
islice(generator, n) | |
elapsed = time() - start |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'epitools' | |
%w[gdbm sdbm cdb].each { |lib| require lib } | |
DBS = [ | |
[GDBM, GDBM], | |
[SDBM, SDBM], | |
[CDBMake, CDB ], | |
] | |
NUM = 100000 |