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
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) |
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
# Allows a Rack application to reuse the Rails-provided CSRF | |
# protection, with the same guarantees and the same token. | |
# Implements token unmasking and other facilties. | |
class Middleware::CSRFAdapter | |
AUTHENTICITY_TOKEN_LENGTH = 32 | |
class InvalidOrMissingToken < StandardError | |
def http_status_code | |
403 | |
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
# Allows a Rack application to reuse the Rails-provided CSRF | |
# protection, with the same guarantees and the same token. | |
# Implements token unmasking and other facilties. | |
class Middleware::CSRFAdapter | |
AUTHENTICITY_TOKEN_LENGTH = 32 | |
class InvalidOrMissingToken < StandardError | |
def http_status_code | |
403 | |
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
# Allows a Rack application to reuse the Rails-provided CSRF | |
# protection, with the same guarantees and the same token. | |
# Implements token unmasking and other facilties. | |
class Middleware::CSRFAdapter | |
AUTHENTICITY_TOKEN_LENGTH = 32 | |
class InvalidOrMissingToken < StandardError | |
def http_status_code | |
403 | |
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 'set' | |
class Eventuality | |
def initialize | |
@events = Set.new | |
@invariants = [] | |
@tasks = [] | |
end | |
def add_single_event(evt) |
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
// Find at which index an element should be inserted | |
// into a sorted array, using binary search | |
function insertionIndexUsingBinarySearch(sortedArray, value, from, to) { | |
if (sortedArray.length === 0) { | |
return 0; | |
} | |
if (typeof(from) === 'undefined') { | |
from = 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
function addCMYKSwatch(name, c, m, y, k) { | |
var myDoc = app.activeDocument; | |
var mySwatch = myDoc.swatches.add(); | |
var color = new CMYKColor(); | |
color.cyan = c; | |
color.magenta = m; | |
color.yellow = y; | |
color.black = k; | |
mySwatch.color = color; | |
mySwatch.name = name; |
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
package mrs | |
import "io" | |
type multiReadSeeker struct { | |
Readers []io.ReadSeeker | |
Pos int64 | |
BytesTotal int64 | |
BytesRead int64 | |
locations []location |