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
# rack_sse.ru | |
# | |
# An example of basic real-time, single-room broadcast chat using Server Sent | |
# Events in plain old Rack. This example does NOT use hijack, or the async | |
# hacks, it just relies on a well implemented threaded Rack server (at time of | |
# writing this will therefore only work with puma!). Other servers should be | |
# fixed to support this, as it is pretty critical to how Rack *should* work on | |
# most servers. The only spec-acceptable failure in this case is not flushing | |
# the content stream on each yield (for which the rack spec has no workaround | |
# today). |
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
import hashlib | |
import hmac | |
import os | |
# BEGIN: FILEPATH: Untitled-1 | |
def encrypt_string(string, key): | |
encrypted = "" | |
for char in string: | |
encrypted += chr(ord(char) ^ key) | |
return encrypted |
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
# We use the cryptography module to implement the encryption and decryption | |
from cryptography.fernet import Fernet | |
# We define a function to generate a symmetric key | |
def generate_key(): | |
# We create a Fernet instance and return its key | |
f = Fernet.generate_key() | |
return f | |
# We define a function to encrypt a given string using a given key |
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 'sinatra/metal' | |
class SinatraMetal < Sinatra::Base | |
include Sinatra::Metal | |
get '/sinatra' do | |
'hello sinatra!' | |
end | |
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 'eventmachine' | |
EM.run do | |
SEKRET_SAUCE = EM.attach( | |
open(RUBY_PLATFORM =~ /mswin|mingw/ ? 'NUL:' : '/dev/null', 'w') | |
) | |
EM.start_server('0.0.0.0', 80, Module.new do | |
def post_init; proxy_incoming_to(SEKRET_SAUCE); end | |
end) | |
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
# = MONKEY PATCH: Memoize Mysql2 Columns | |
# | |
# Reduces SHOW FIELDS selects in production to essentially 0 calls. | |
# | |
# == Reason: | |
# | |
# * We have some pages that are (with rails 3.0.12) generating nearly 1200 SHOW | |
# FIELDS sql statements. | |
# * These come from ActiveRecord::Associations during complex join semantics. | |
# * Esentially, through some relations, Arel::Table instances don't have |
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
[Unit] | |
Description=/opt/bin/%N | |
After=network.target | |
[Service] | |
SecureBits=no-setuid-fixup-locked noroot-locked keep-caps | |
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 | |
AmbientCapabilities=CAP_NET_BIND_SERVICE | |
CapabilityBoundingSet=CAP_NET_BIND_SERVICE | |
SystemCallFilter=@basic-io @network-io @io-event |
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 rackup | |
require 'forward' | |
run Rack::Forwarder.new('google.com') |
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 zsh | |
set -e | |
autoload -U tcp_open | |
tcp_open $1 $2 zmq | |
msg=$(cat -) | |
tcp_send -s zmq $(print -nf '\x01\x00\x%02x\x00%s' $((1 + ${#msg})) "$msg") | |
tcp_close zmq |
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 Safeware | |
def initialize(app) | |
@app = app | |
end | |
# This dup pattern is used frequently to avoid race conditions on state stored | |
# inside this middleware. It's not foolproof, but if you're just using | |
# single-reference instance variables (instance variables with primitive | |
# values (not data structures)) then it works well. |
NewerOlder