Skip to content

Instantly share code, notes, and snippets.

View Niall47's full-sized avatar
🐢
Doing a learn about codes and that

Niall47

🐢
Doing a learn about codes and that
View GitHub Profile
@Niall47
Niall47 / email.feature
Created August 15, 2019 07:51
Mailosaur Ruby email test template
Feature: I look through emails
Scenario: I look through emails
Given I check the email has been recieved
And I search for an email with a "subject" of "Notification of application"
Then I delete all emails from my inbox
And I check the email has been recieved
@Niall47
Niall47 / scrabble.rb
Created October 23, 2021 21:34
scrabble scoring
scores = {
/[AEIOULNRST]/ => 1,
/[DG]/ => 2,
/[BCMP]/ => 3,
/[FHVWY]/ => 4,
/[K]/ => 5,
/[JX]/ => 8,
/[QZ]/ => 10
}
input = gets
.chomp
.upcase
.gsub(/[^A-Z]/i, '')
.chars
puts "isogram" if input == input.uniq
resistor_colours = ['black', 'brown', 'red', 'orange', 'yellow', 'green', 'blue', 'violet', 'grey', 'white']
input_array = gets.chomp.gsub(' ', '').split('-')
puts resistor_colours.find_index(input_array[0]).to_s + resistor_colours.find_index(input_array[1]).to_s
string1 = 'GAGCCTACTAACGGGAT'.chars
string2 = 'CATCGTAATGACGGCCT'.chars
diff = 0
string1.each_with_index do |character, index|
if character != string2[index]
diff +=1
end
end
puts diff
=begin
Atbash cipher
The Atbash cipher is a type of ancient encryption created to encode messages in Hebrew.
At its heart is a very simple substitution cipher that transposes all the letters in the alphabet backwards. The first letter in the alphabet is replaced by the the last letter so A -> Z, B -> Y etc.
Plain: abcdefghijklmnopqrstuvwxyz
Cipher: zyxwvutsrqponmlkjihgfedcba
It is obviously a very weak encryption mechanism!
@Niall47
Niall47 / luhn.rb
Last active November 24, 2021 17:45
=begin
Luhn check
The Luhn check is a simple checksum, famously used to check credit card numbers are at least possibly valid.
Take this number:
4539 3195 0343 6467
The first thing we do is, starting on the right, double every second number and, if that number is greater than 9, subtract 9 from it:
4539319503436467
^ ^ ^ ^ ^ ^ ^ ^
8569 6195 0383 3437
The next step is to add all the digits:
=begin
Run length encodingRun-length encoding (RLE) is a simple form of data compression, where runs (consecutive data elements) are replaced by just one data value and count.
For example we can represent the original 53 characters with only 13.
"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB" -> "12WB12W3B24WB"
RLE allows the original data to be perfectly reconstructed from the compressed data, which makes it a lossless data compression."AABCCCDEEEE" -> "2AB3CD4E" -> "AABCCCDEEEE"
For simplicity, you can assume that the unencoded string will only contain the letters A through Z (either lower or upper case) and whitespace.
This way data to be encoded will never contain any numbers and numbers inside data to be decoded always represent the count for the following character.
=end
# Usage example
@Niall47
Niall47 / slider.html
Created December 9, 2021 09:33
Power sliders for Raspberry Pi PWM pins. runs on port 8081, give it the Raspberry Pi's IP if you're connecting remotely
<!DOCTYPE html>
<html>
<style>
.rangeslider{
width: 50%;
}
.myslider {
-webkit-appearance: none;
@Niall47
Niall47 / collatz.rb
Last active December 17, 2021 09:01
=begin
Collatz Conjecture
Hint: recursion!
The Collatz Conjecture or 3x+1 problem can be summarized as follows:
Take any positive integer n. If n is even, divide n by 2 to get n / 2. If n is odd, multiply n by 3 and add 1 to get 3n + 1. Repeat the process indefinitely. The conjecture states that no matter which number you start with, you will always reach 1 eventually.
Given a number n, return the number of steps required to reach 1.
Example:
Starting with n = 12, the steps would be as follows:
12
6