This file contains 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 python | |
import contextlib as __stickytape_contextlib | |
@__stickytape_contextlib.contextmanager | |
def __stickytape_temporary_dir(): | |
import tempfile | |
import shutil | |
dir_path = tempfile.mkdtemp() | |
try: | |
yield dir_path |
This file contains 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
# and here is the script in case anyone is interested :) | |
import nuke | |
def getTheCornerpinAsMatrix(): | |
projectionMatrixTo = nuke.math.Matrix4() | |
projectionMatrixFrom = nuke.math.Matrix4() | |
#dir(projectionMatrix) | |
theCornerpinNode = nuke.selectedNode() | |
imageWidth = float(theCornerpinNode.width()) | |
imageHeight = float(theCornerpinNode.height()) |
This file contains 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
PAYLOAD_SIZE = 15 * 1024 * 1024 | |
CHUNK_SIZE = 65 * 1024 # Roughly one socket buffer | |
class StufferBody | |
def each | |
rng = Random.new(123) | |
whole_chunks, rem = PAYLOAD_SIZE.divmod(CHUNK_SIZE) | |
whole_chunks.times do | |
yield(rng.bytes(CHUNK_SIZE)) | |
end | |
yield(rng.bytes(rem)) if rem > 0 |
This file contains 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
# In a couple of tables we have VARBINARY columns which either encode a packed | |
# integer of some kind, or a checksum (which is commonly shared as a hexadecimal). | |
# This module allows rapid definition of such columns and accessors for them. For example, | |
# imagine you want to store a CRC32 value - which fits into a uint4 | |
# | |
# class RecordWithChecksum < ActiveRecord::Base | |
# extend PackedColumn | |
# packed_value_column :crc32, pattern: 'V' | |
# end | |
# |
This file contains 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 'zlib' | |
# A fairly naive generator of payloads which, having the same size, will produce an identical CRC32 checksum | |
def produce_bytes_at_iteration(bytebag_size, random_seed, iter) | |
rng = Random.new(random_seed) | |
iter.times do | |
rng.bytes(bytebag_size) | |
end | |
rng.bytes(bytebag_size) | |
end |
This file contains 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 'bundler' | |
Bundler.setup | |
require 'benchmark' | |
require 'benchmark/ips' | |
require_relative '../lib/zip_tricks' | |
some_randomness = StringIO.new(Random.new.bytes(800 * 1024)) | |
rackup_path = File.join(__dir__, 'webserver.ru') |
This file contains 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 ZipTricks::OutputEnumerator | |
DEFAULT_WRITE_BUFFER_SIZE = 65 * 1024 | |
# Creates a new OutputEnumerator. | |
# | |
# @param streamer_options[Hash] options for Streamer, see {ZipTricks::Streamer.new} | |
# It might be beneficial to tweak the `write_buffer_size` to your liking so that you won't be | |
# doing too many write attempts and block right after | |
# @param write_buffer_size[Integer] By default all ZipTricks writes are unbuffered. For output to sockets | |
# it is beneficial to bulkify those writes so that they are roughly sized to a socket buffer chunk. This | |
# object will bulkify writes for you in this way (so `each` will yield not on every call to `<<` from the Streamer |
This file contains 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
TERMINATORS = ["\n", ";"] | |
ESC = "\\" | |
QUOTES = ['"', "'"] | |
class c: | |
""" | |
Will be at the start of a list representing an expression | |
in curly braces. Every c() is equal to any other c() | |
""" |
This file contains 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
module Kelder | |
module PrefixKeyWithToken | |
# Prefix all generated blob keys with the tenant. Do not | |
# use slash as a delimiter because it needs different escaping | |
# depending on the storage service adapter - in some cases it | |
# might be significant, in other cases it might get escaped as a path | |
# component etc. | |
def generate_unique_secure_token | |
tenant_slug = Apartment::Tenant.current.split('_').last | |
"#{tenant_slug}-#{super}" |
This file contains 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 MultipartRangesWriter | |
ALPHABET = ('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a | |
def initialize | |
# RFC1521 says that a boundary "must be no longer than 70 characters, not counting the two leading hyphens". | |
# Modulo-based random is biased but it doesn't matter much for us | |
@boundary = SecureRandom.bytes(64).unpack("C*").map {|b| ALPHABET[b % ALPHABET.length] }.join | |
end | |
class NullWriter < Struct.new(:offset) |