This file contains hidden or 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
#!/bin/bash | |
# First change your Rails dependency in the Gemfile to 3.2.12. | |
# Make sure afterwards that the commit includes the update to the Rails version | |
# and that it contains the JSON gem version 1.7.7. | |
git co -b patch_CVE-2013-0269_CVE-2013-0276 | |
bundle update rails | |
bundle update json | |
git add -A |
This file contains hidden or 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
In the resque web interface, if you see a process that is hanging for a long | |
time, you can figure out what it's waiting on by looking at the PID. Say | |
we see pid 4894 taking a long time. In the console do: | |
$ sudo strace -p 4894 | |
Process 4894 attached - interrupt to quit | |
wait4(15045, | |
The strace just hangs there, and we think that perhaps the process isn't | |
doing anything. If you look at the man page for wait4, you see that the |
This file contains hidden or 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
vmstat is a helpful tool for figuring out performance problems on servers. | |
user@server-prod-db01:~$ vmstat 5 | |
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- | |
r b swpd free buff cache si so bi bo in cs us sy id wa | |
1 0 10860 51884 41656 3712392 0 0 1297 107 0 0 10 3 84 3 | |
0 0 10860 50388 41668 3713204 0 0 41 446 1409 1173 6 2 91 1 | |
The "b" column shows blocked processes waiting for IO. In this case it's 0, which is a good thing. |
This file contains hidden or 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
;; Clojure library clj-yaml deserializes into arbitrary Java classes | |
user=> (require '[clj-yaml.core :as yaml]) | |
nil | |
user=> (yaml/parse-string "!!java.io.File") | |
#<File > |
This file contains hidden or 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
(defn sha-512 | |
"Return the SHA-512 of the given string" | |
[data] | |
(let [md (. java.security.MessageDigest getInstance "SHA-512")] | |
(. md update (.getBytes data)) | |
(let [bytes (. md digest)] | |
(reduce #(str %1 (format "%02x" %2)) "" bytes)))) | |
(defn hash-repeatedly | |
"Hash the given string n number of times" |
This file contains hidden or 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
(defn all-functions | |
([root-n] (all-functions root-n [])) | |
([cur fns] | |
(if (= java.util.ArrayList (class cur)) | |
(if (empty? cur) | |
fns | |
(map #(all-functions % fns) cur)) | |
(if (= org.jruby.ast.DefnNode (class cur)) | |
(all-functions (.childNodes cur) (conj fns cur)) | |
(all-functions (.childNodes cur) fns))))) |
This file contains hidden or 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
1.9.3-p125 :036 > p = DotHash::Properties.new({}) | |
=> #<DotHash::Properties:0x007f8cf408a308 @hash={}> | |
1.9.3-p125 :037 > p = DotHash::Properties.new({:foo => :bar}) | |
=> #<DotHash::Properties:0x007f8cf4067740 @hash={:foo=>:bar}> | |
1.9.3-p125 :038 > p.respond_to?(:foo) | |
=> false | |
1.9.3-p125 :039 > p.foo | |
=> :bar |
This file contains hidden or 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
# These MIME types, which we don't use, are vulnerable per CVE-2013-0156 | |
ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::XML) | |
ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::YAML) |
This file contains hidden or 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 'minitest/autorun' | |
# Demonstrates the way that refinements are applied in Ruby 2.0.0preview1. | |
module RegularStringCounts | |
refine String do | |
def num_caps | |
self.scan(/[A-Z]/).count | |
end | |
end |
This file contains hidden or 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 :next | |
end | |
a = Node.new | |
b = Node.new | |
c = Node.new | |
a.next = b | |
b.next = c |