Skip to content

Instantly share code, notes, and snippets.

View broguinn's full-sized avatar

Braden O'Guinn broguinn

View GitHub Profile
@broguinn
broguinn / hexadecimal.rb
Created August 30, 2013 00:56
hexadecimal
def hexadecimal(hex_number)
hex = 0
letters = { "a" => 10, "b" => 11, "c" => 12, "d" => 13, "e" => 14, "f" => 15}
hex_number = hex_number.split("").map do |digit|
if letters.keys.include?(digit)
letters[digit]
else
digit
end
@broguinn
broguinn / prime.rb
Created August 30, 2013 00:57
prime
def is_prime?(number)
if number < 2 || !(number.is_a?(Integer))
false
else
(2..((number ** 0.5).floor)).all? { |possible| number % possible != 0 } ? true : false
end
end
def prime(number)
if number < 1 || !(number.is_a?(Integer))
@broguinn
broguinn / raindrops.rb
Created August 30, 2013 00:58
raindrops
def raindrops(number)
raise TypeError.new "the number must be an integer" if !(number.is_a?(Integer))
phrase = ""
phrase << "Pling" if number % 3 == 0
phrase << "Plang" if number % 5 == 0
phrase << "Plong" if number % 7 == 0
(phrase == "") ? number.to_s : phrase
@broguinn
broguinn / luhn.rb
Created August 30, 2013 00:58
luhn
def luhn(id, check=0)
id = id.to_s.split("").reverse.each_with_index.map do |digit, index|
digit = digit.to_i
if (index + 1) % 2 == 0
if digit * 2 > 9
(digit * 2) - 9
else
digit * 2
end
else
@broguinn
broguinn / queens.rb
Created August 30, 2013 00:59
queens
def queens_attack?(white_coords, black_coords)
raise ArgumentError.new "Takes only two coordinates" if white_coords.length != 2 || !(white_coords.is_a?(Array))
raise ArgumentError.new "Takes only two coordinates" if black_coords.length != 2 || !(black_coords.is_a?(Array))
raise ArgumentError.new "The coordinates must not be the same" if black_coords == white_coords
white_coords.zip(black_coords).flatten.each do |coordinate|
raise TypeError.new "The coordinates must be between 0 and 7" if coordinate < 0 || coordinate > 7
end
@broguinn
broguinn / saddlepoints.rb
Created August 30, 2013 01:00
saddlepoints unfinished
require 'matrix'
class Matrix
def saddlepoints
saddles = []
self.each_with_index do |e, each_row, each_col|
if self.row(each_row).all? { |rcell| rcell <= e } && self.row(each_col).all? { |ccell| ccell >= e }
saddles << [each_row, each_col]
end
end
@broguinn
broguinn / ASQ Map
Created January 23, 2015 17:23
ASQ map
//In asynquence-contrib
var emptyItems = [],
sq = ASQ();
sq.map(emptyItems, function(item, done){
// do some things to item
item.values = [];
done(item);
});

How to kill your VM: limits.d and the Magic of dotfiles

I was benchmark testing StatsD on my VM this week, and was seeing 40% package drop rate right out of the box. So, I increased my UNIX limits by creating a /usr/security/limits.d/limits.conf as such:

*               soft    nofile           unlimited
*               hard    nofile           unlimited
*               soft    nproc            unlimited
*               hard    nproc            unlimited
@broguinn
broguinn / lazy.diff
Created January 9, 2018 18:26
Patch for lazyload
index 5be7b5083434..4d845f5dd0aa 100644
--- a/htdocs/assets/js/lib/lazyload.js
+++ b/htdocs/assets/js/lib/lazyload.js
@@ -1,5 +1,9 @@
-// set up lazyload, which looks for data-img properties on img tags and automatically loads them lazily
-// src: https://github.com/verlok/lazyload
+/* set up lazyload, which looks for data-img properties on img tags and automatically loads them lazily
+ src: https://github.com/verlok/lazyload
+ version 10.4.x
+ We've modified from the original file by removing the IntersectionRatio check in onIntersection as it
// We know that b is the closing char
// Change this if ever the order isn't known
const formsPair = (a: string, b: string): boolean => {
const forms = (a === "{" && b === "}") ||
(a === "(" && b === ")") ||
(a === "[" && b === "]");
console.log(["forms pair?", forms])
return forms;
};