Skip to content

Instantly share code, notes, and snippets.

@kyledrake
kyledrake / gist:4956808
Created February 14, 2013 22:03
Testing different binary protocol implementations
require 'json'
require 'bson'
require 'msgpack'
require 'benchmark'
#require 'ruby_protobuf'
test_hash = {'string' => 'test string', 'float' => 5}
json_results = Benchmark.measure do
100_000.times do
@kyledrake
kyledrake / websocket_server.rb
Created February 26, 2013 19:28
debugging..
#!/usr/bin/env ruby
require 'celluloid/io'
require 'json'
require 'websocket'
class FileWriter
include Celluloid
def initialize
#!/usr/bin/env ruby
require 'celluloid/io'
require 'json'
require 'websocket'
class WebsocketClient
include Celluloid::IO
def initialize(host, port)
require 'rubygems'
require 'bundler'
Bundler.require
require './application'
namespace :assets do
desc 'compile assets'
task :compile => [:compile_js, :compile_css] do
end
@kyledrake
kyledrake / test.rb
Created March 13, 2013 00:21
Idea for storing an SSN (or CC#, or anything confidential) on a database, preventing an attacker from looking at it by hiding the private key on an offline machine using rbnacl.
require 'rbnacl'
# Idea for storing an SSN (or CC#, or anything confidential) on a database, preventing an attacker from looking at it by hiding the private key on an offline machine.
# Private key would be generated somewhere other than the web application.
private_key = Crypto::PrivateKey.generate
# Given to a web application:
@kyledrake
kyledrake / ssl.rb
Created March 13, 2013 00:37
Idea for storing an SSN (or CC#, or anything confidential) on a database, preventing an attacker from looking at it if they've compromised the database the encrypted text is in, by hiding the private key on an offline machine, and encrypting the text with the public key (which it theoretically cannot read itself without the private key)
require 'openssl'
public_key = OpenSSL::PKey::RSA.new(File.read('./public.pem'))
cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
cipher.encrypt
cipher.key = random_key = cipher.random_key
cipher.iv = random_iv = cipher.random_iv
encrypted_data = cipher.update('SSN number')
encrypted_data << cipher.final
@kyledrake
kyledrake / gist:5696630
Last active December 18, 2015 00:29
How do I make try_files work here..
# So, the idea here is to take USERNAME.neocities.org, and have it serve
# from /home/web/neocities/public/sites/USERNAME/REQUESTED_FILENAME
# When I try to use it, I get in error.log:
# invalid number of arguments in "try_files" directive in /etc/nginx/sites-enabled/neocities:5
server {
root /home/web/neocities/public/sites;
server_name neocities.org www.neocities.org ~^(?<subdomain>.+)\.neocities.org$;
server {
root /home/web/neocities-web/public;
server_name neocities.org www.neocities.org;
# location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
# expires 60s;
# log_not_found off;
# }
try_files $uri @neocities;
@kyledrake
kyledrake / gist:5906731
Last active December 19, 2015 05:49
Current SSL Cipher config for NeoCities, pulled from http://blog.cloudflare.com/new-ssl-vulnerabilities-cloudflare-users-prot
ssl_ciphers ECDHE-RSA-AES128-SHA256:AES128-GCM-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH;
@kyledrake
kyledrake / gist:5915757
Last active December 19, 2015 06:59
Using Ruby to fuck up a file system
```ruby
require 'fileutils'
require 'securerandom'
2_000_000.times do |site|
site_name = SecureRandom.hex[0...20]
puts site_name
Dir.mkdir File.join('./', 'sites', site_name)