Skip to content

Instantly share code, notes, and snippets.

@epitron
epitron / gist:887914c6877f4069eb63
Created June 5, 2014 05:48
Things that depend on GnuTLS...
$ apt-cache rdepends libgnutls26 | grep -v lib
Reverse Depends:
aiccu
vino
qemu-kvm
exim4-daemon-light
exim4-daemon-heavy
cups
xen-utils-4.1
wine1.4-amd64
@epitron
epitron / tz
Last active August 29, 2015 14:03
#!/bin/bash
#
# by Sairon Istyar, 2012
# distributed under the GPLv3 license
# http://www.opensource.org/licenses/gpl-3.0.html
#
# Source:
# https://github.com/saironiq/shellscripts/blob/master/torrentz_eu/torrentz_eu.sh
#
### CONFIGURATION ###
@epitron
epitron / hanoi.rb
Created August 15, 2014 22:01
Crazy 3-line tower of Hanoi solver.
puts "How many disks? "
n = STDIN.gets.to_i
x = 1
while (x < (1 << n))
puts "move from pole #{(x&x-1)%3} to pole #{((x|x-1)+1)%3}"
x += 1
end
@epitron
epitron / unfiglet-dorei-slow.rb
Last active August 29, 2015 14:05
Figlet-based CAPTCHA breaker (for IRC bots) -- accelerated!
require 'epitools'
figlet_left = File.readlines('./figlet.input')
def get_first_char(i, arr)
arr.map { |x| x[0..i] }
end
def remove_first_char(i, arr)
arr.map { |x| x.slice(i..-1) }
@epitron
epitron / kv_bench.rb
Last active May 18, 2020 05:21
Benchmark Ruby's various key/value databases (GDBM, SDBM, CDB)
require 'epitools'
%w[gdbm sdbm cdb].each { |lib| require lib }
DBS = [
[GDBM, GDBM],
[SDBM, SDBM],
[CDBMake, CDB ],
]
NUM = 100000
@epitron
epitron / primes.py
Last active April 20, 2021 07:42
Fast prime number generators in Python
#!/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
@epitron
epitron / lstat_pyramid.txt
Last active August 29, 2015 14:07
Ruby's "lstat pyramid" (this is executed for every file it attempts to open)
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
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
# examples
spec = {
"apiKey" => String,
"language" => ["en", "ru"],
"clientData" => {
"userName" => String,
"userCity" => String,
"userPhoneNo" => String,
"userPassword" => String
@epitron
epitron / background.js
Created October 17, 2014 18:38
Sample Chrome Extension
// 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);
});