Skip to content

Instantly share code, notes, and snippets.

View cjjuice's full-sized avatar
💭
🚀

C.J. Bordeleau / r4v3n cjjuice

💭
🚀
View GitHub Profile
@cjjuice
cjjuice / string-reverse-benchmark.rb
Last active October 2, 2019 13:58
String reverse benchmarks
[179] pry(main)> n = 1000000
=> 1000000
[180] pry(main)> Benchmark.bm(7) do |x|
[180] pry(main)* x.report('1:') { ->(str) { n.times { chars = str.chars; (1..chars.length).to_a.tap { |a| chars.each_with_index { |c, i| a[-i-1] = c } }.join } }.call('r4v3n') }
[180] pry(main)* x.report('2:') { ->(str) { n.times { [].tap { |a| chars = str.chars; str.size.times { a << chars.pop } }.join } }.call('r4v3n') }
[180] pry(main)* x.report('3:') { ->(str) { n.times { str.size/2.times { |i| str[i], str[-i-1] = str[-i-1], str[i] }; str } }.call('r4v3n') }
[180] pry(main)* x.report('4:') { ->(str) { n.times { str.reverse } }.call('r4v3n') }
[180] pry(main)* end
user system total real
1: 2.626973 0.019897 2.646870 ( 2.657133)
@cjjuice
cjjuice / checksum_funcs.sh
Created March 12, 2019 13:33
Bash functions to print and check sha256 checksums
print_checksum() {
echo $1 | shasum -a 256
}
verify_checksum() {
checksum=$(echo $1 | shasum -a 256)
if [[ $2 == "$checksum" ]]; then
echo "valid"
else
printf "invalid:\n$1 ($checksum)\nvs\n$2\n"

Keybase proof

I hereby claim:

  • I am cjjuice on github.
  • I am veritatem (https://keybase.io/veritatem) on keybase.
  • I have a public key ASCX1WJ76AdPF1MCXjUeszrCorA9Ufq-Ezh4_1YtVvOLvQo

To claim this, I am signing this object:

# write a method that takes the array of hashes as an argument and
# if any of the values of the element hashes are nil,
# remove the hash from the parent array.
# i.e input: [{a: 4, b: nil}, {a: 5, b: 6}, {a: nil, b: 2}]
# output: [{a:5, b: 6}]
# Definition for singly-linked list.
# class ListNode
# attr_accessor :val, :next
# def initialize(val)
# @val = val
# @next = nil
# end
# end
# @param {ListNode} l1
# @param {Integer[]} nums
# @param {Integer} target
# @return {Integer[]}
def two_sum(nums, target)
solution = nil
offset = 1
while solution == nil
nums.each_with_index do |num, i|
if nums[i+offset] && num + nums[i+offset] == target
solution = [i, i+offset]
@cjjuice
cjjuice / keybase.md
Last active April 13, 2016 15:52
keybase proof

Keybase proof

I hereby claim:

  • I am cjjuice on github.
  • I am cjjuice (https://keybase.io/cjjuice) on keybase.
  • I have a public key whose fingerprint is DDEA 9E9C BE58 D506 E8AE B66B C4DF 0485 D543 7128

To claim this, I am signing this object: