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($) { | |
// 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: |
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
# 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' |
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 '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 |
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
# 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' |
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
# 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 |
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 Node | |
attr_accessor :data, :left, :right | |
def initialize(data) | |
@left = nil | |
@right = nil | |
@data = data | |
end | |
include Comparable |
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
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, |
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 "time" | |
require "pry" | |
require "thread" | |
class Logger | |
def initialize | |
@mutex = Mutex.new | |
end | |
def log_error(error) |
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 Regexp | |
def self.quantifier(min,max) | |
if !max | |
if min == 0 | |
"*" | |
elsif min == 1 | |
"+" | |
else | |
raise "Invalid" | |
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
class ArgumentSplitter { | |
static split(argumentString) { | |
return (new this(argumentString)).parse().arguments | |
} | |
constructor(argumentString) { | |
this.argumentString = argumentString | |
this.arguments = null | |
} |
NewerOlder