Skip to content

Instantly share code, notes, and snippets.

@apeiros
apeiros / submitForm.js
Created September 9, 2014 06:31
send a "virtual" form with values from JS
;(function($) {
// Sends a (virtual) form with values.
// Unlike an AJAX Post/Get, this actually makes the browser send the form and process the response. Which means that
// the site is being changed (or a file will be downloaded)
//
// Example usage:
// $.submitForm('/my/resource', {'someFormParam': 'andItsValue'}, {'method': 'PUT'});
//
// Notes:
@apeiros
apeiros / https_echo.rb
Created January 29, 2012 19:21
HTTPS echo server, using only OpenSSL and TCPServer
# use the following commands to create key.pem & cert.pem
# openssl genrsa -out key.pem
# openssl req -new -x509 -key key.pem -out cert.pem -days 1095
# open your browser and use
# https://127.0.0.1:8080/
require 'socket'
require 'openssl'
require 'cgi'
@apeiros
apeiros / seeds.rb
Created May 26, 2011 17:22
A beefed up seeds file for rails
require 'pp'
puts "Seeding for env '#{Rails.env}'"
# disable AR logger
old_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil unless $VERBOSE
env_seed_file = "#{Rails.root}/db/data/seed/#{Rails.env.downcase}/seeds.rb"
# first load yaml files that is "base" loading
@apeiros
apeiros / irbrc
Created April 16, 2011 23:32
First draft of my rewritten irbrc - use with caution...
# encoding: utf-8
if defined?(Encoding) then
Encoding.default_external = 'utf-8'
Encoding.default_internal = 'utf-8'
else
$KCODE = 'utf-8'
end
ENV["LANG"] = 'en_US.UTF-8'
@apeiros
apeiros / extract_log.rb
Last active February 16, 2018 15:41
Extract pieces from line-based logfiles
# WARNING: lots of edge-cases are not properly handled. this is just code I wrote to inspect some
# rails logs by hand in pry where I could easily deal manually in edge-cases.
# however, feel free to fork and fix the edge-cases (and tell me about it!)
#
# use like this:
# start_time = Time.local(2017,1,1)
# end_time = Time.local(2017,1,2)
# puts rails_log_within("path/to/logfile.log", start_time, end_time)
require "time" # Time.iso8601 is stdlib, not core
@apeiros
apeiros / binary_tree.rb
Last active February 8, 2018 16:10 — forked from CodePint/binary_tree.rb
binary tree and nodes
class Node
attr_accessor :data, :left, :right
def initialize(data)
@left = nil
@right = nil
@data = data
end
include Comparable
Stats = Struct.new(:strength, :dexterity, :endurance, :intelligence, :education, :social_status) do
def self.random(min: 5, max: 10)
new(*Array.new(6) { rand(min..max) })
end
def +(other)
self.class.new(
strength+other.strength,
dexterity+other.dexterity,
endurance+other.endurance,
require "time"
require "pry"
require "thread"
class Logger
def initialize
@mutex = Mutex.new
end
def log_error(error)
class Regexp
def self.quantifier(min,max)
if !max
if min == 0
"*"
elsif min == 1
"+"
else
raise "Invalid"
end
class ArgumentSplitter {
static split(argumentString) {
return (new this(argumentString)).parse().arguments
}
constructor(argumentString) {
this.argumentString = argumentString
this.arguments = null
}