Skip to content

Instantly share code, notes, and snippets.

View wjessop's full-sized avatar
🤖

Will Jessop wjessop

🤖
View GitHub Profile
@wjessop
wjessop / lock.rb
Created September 26, 2016 14:26
with_exclusive_lock("my_operation") do
# Something that can only happen one at a time
end
def with_exclusive_lock(lock_name, &block)
lock_file_name = "/tmp/#{lock_name}.lock"
FileUtils.touch(lock_file_name)
lock_file = File.new(lock_file_name)
lock_file.flock(File::LOCK_EX)
yield
Ubuntu:
root@willtesting:/var/log# openssl ciphers -v | grep TLS
ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(256) Mac=AEAD
ECDHE-ECDSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESGCM(256) Mac=AEAD
ECDHE-RSA-AES256-SHA384 TLSv1.2 Kx=ECDH Au=RSA Enc=AES(256) Mac=SHA384
ECDHE-ECDSA-AES256-SHA384 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AES(256) Mac=SHA384
DHE-DSS-AES256-GCM-SHA384 TLSv1.2 Kx=DH Au=DSS Enc=AESGCM(256) Mac=AEAD
DHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=DH Au=RSA Enc=AESGCM(256) Mac=AEAD
DHE-RSA-AES256-SHA256 TLSv1.2 Kx=DH Au=RSA Enc=AES(256) Mac=SHA256
package main
import "fmt"
func main() {
fmt.Println("Hello world!")
}
func (r *repo_handle) get_tar_file() (string, error) {
target_dir, tmpdir_err := ioutil.TempDir("", "captain_app_tar")
log.Println("Got temp directory for app tar", target_dir)
if tmpdir_err != nil {
return "", tmpdir_err
}
archive_path := target_dir + "/" + "app.tar"
log.Println("Going to create the tar archive at path", archive_path)
[sc-chi] root@proxy-02:~# docker insert slsdhf app.tar /tmp/app.tar
[sc-chi] root@proxy-02:~# echo $?
0
require 'minitest/autorun'
class TestWords < Minitest::Test
def test_that_similar_words_are_found
assert_equal one_off_words("moor", ["door", "moot", "boot", "boots"]), ["door", "moot"]
end
def test_fake_failure
assert_equal one_off_words("moor", ["door", "moot", "boot", "boots"]), ["door", "moot", "fuckers"]
end
class Array
def xor(key)
a = dup
a.length.times { |n| a[n] ^= key[n % key.size] }
a
end
end
stra = "123abc"
strb = "123adc"
package main
import (
"github.com/wjessop/go-piglow"
"log"
)
func main() {
var p *piglow.Piglow
var err error
require 'thread'
LAST_VAL = 8
q = Queue.new
(0..LAST_VAL).to_a.shuffle.each {|i| q << i}
vals = []
next_val = 0
loop do
puts "popping the stack"
@wjessop
wjessop / api.rb
Last active December 20, 2015 04:39
I need a "rolling timeout" for some code. If something doesn't happen for x seconds, timeout, but if it does, reset the timer. The Ruby Timeout module doesn't help with this, it provides only a static timeout.
# The API I thought up, This example will
# sleep for 16 seconds (4 * 4 seconds + 5 seconds)
begin
RollingTimeout.new(5) {|timer|
sleep(4)
timer.reset
sleep(4)
timer.reset
sleep(4)