Skip to content

Instantly share code, notes, and snippets.

@benmmurphy
benmmurphy / metadata.gz
Created January 30, 2013 09:20
Example metadata.gz
--- !ruby/object:Gem::Specification
name: xpath
version: !ruby/object:Gem::Version
prerelease: false
segments:
- 0
- 1
- 4
version: 0.1.4
platform: ruby
module ApplicationHelper
def escape_js(str)
str.gsub('<', '\u003C').gsub('>', '\u003E').gsub('&', '\u0026').gsub("\u2028", '\u2028').gsub("\u2029", '\u2029').html_safe
end
end
@benmmurphy
benmmurphy / gist:4705923
Created February 4, 2013 09:58
oj json default behaviour
irb(main):001:0> require 'oj'
=> true
irb(main):002:0> Oj
=> Oj
irb(main):003:0> Oj.dump(Object.new)
=> "{\"^o\":\"Object\"}"
irb(main):004:0> Oj.load("{\"^o\":\"Object\"}")
=> #<Object:0x0000010115c5f0>
@benmmurphy
benmmurphy / gist:4706099
Created February 4, 2013 10:45
csv object loading
irb(main):004:0> CSV.dump([Object.new])
=> "class,Object\n\n\n"
irb(main):005:0> CSV.load(CSV.dump([Object.new]))
=> [#<Object:0x00000100ae90d8>]
@benmmurphy
benmmurphy / gist:5382629
Last active December 16, 2015 05:09
dual palindromic primes of n digits
public static int count(int digits) {
if (digits % 2 == 0) {
return countEven(digits);
} else {
return countOdd(digits);
}
}
public static int countEven(int digits) {
// +1 -1
@benmmurphy
benmmurphy / gist:5430539
Created April 21, 2013 18:29
1st Large
#!/usr/bin/env ruby
def is_palindrome(n)
s = n.to_s
s.reverse == s
end
def all
result = []
(1..10000000).each do |sqrt|
@benmmurphy
benmmurphy / README.md
Last active December 17, 2015 11:09
TIMED_WAIT verifier

replays last FIN-ACK in order to check if the other side correctly implements TIMED-WAIT. other side should be first to close the connection. with http this can be done in curl by forcing http/1.0 mode.

curl -0 -d 'lolol=lololol' http://TARGET/wtwtwt
tcpdump -S 'tcp port 80' -l | ./replayer.rb TARGET 80 YOUR_HOST_AS_APPEARS_IN_TCPDUMP

Example of it working and showing the other side correctly handling TIMED-WAIT:

root@midway:~# tcpdump -S 'tcp port 80' -l | ./replayer.rb 173.194.41.67 80 ip-10-250-157-181.eu-west-1.compute.internal
OMG IM RUNNING

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode

@benmmurphy
benmmurphy / gist:5935199
Created July 5, 2013 15:10
redis-slave funny business
[21736] 04 Jul 13:52:16 # /lib/libc.so.6(memcpy+0xe1) [0x7f09264322c1]
[21736] 04 Jul 13:52:16 # /lib/libc.so.6(memcpy+0xe1) [0x7f09264322c1]
[21736] 04 Jul 13:52:16 # /usr/bin/redis-server(sdscatlen+0x4f) [0x41029f]
[21736] 04 Jul 13:52:16 # /usr/bin/redis-server(readQueryFromClient+0x45) [0x416e95]
[21736] 04 Jul 13:52:16 # /usr/bin/redis-server(aeProcessEvents+0x135) [0x40b1a5]
[21736] 04 Jul 13:52:16 # /usr/bin/redis-server(aeMain+0x2e) [0x40b4fe]
[21736] 04 Jul 13:52:16 # /usr/bin/redis-server(main+0xf7) [0x40a407]
[21736] 04 Jul 13:52:16 # /lib/libc.so.6(__libc_start_main+0xfd) [0x7f09263c8c4d]
[21736] 04 Jul 13:52:16 # /usr/bin/redis-server() [0x40a51d]
@benmmurphy
benmmurphy / TLSLoggingProvider.java
Last active April 30, 2024 12:11
SSLKEYLOGFILE for java
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.FileSystems;
import java.nio.file.StandardOpenOption;
import java.security.InvalidAlgorithmParameterException;
import java.security.Provider;
import java.security.SecureRandom;
import static java.util.Arrays.*;
public class JavaDoc {
public String name() {
return asList('I', 'x',
'`', 'u',
'`', 'a',
'x', 'd',
'q', 'f')
.stream()