Skip to content

Instantly share code, notes, and snippets.

View codenamev's full-sized avatar
🌩️

Valentino Stoll codenamev

🌩️
View GitHub Profile
@codenamev
codenamev / file-contains-in-x-lines.sh
Created July 29, 2022 18:55
Search files for line
#!/usr/bin/env bash
# usage: file-contains-in-x-lines matchy path/to/file
# Check if single file contains "matchy" in the first 10 lines
head -n 10 $2 | grep -m 1 $1
@codenamev
codenamev / tmux-test-runner.vim
Created November 14, 2019 15:20
Run specs from vim in another tmux pane.
map <silent> <Leader>rl :w<cr>:silent call RunCurrentLineInTest('!ts bundle exec rspec')<cr>:silent redraw!<cr>
map <silent> <Leader>rt :w<cr>:silent call RunCurrentTest('!ts bundle exec rspec')<cr>:silent redraw!<cr>
" Test runner helpers
function! RunCurrentTest(rspec_type)
let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\|_test.rb\)$') != -1
if in_test_file
call SetTestFile()
if match(expand('%'), '\.feature$') != -1
@codenamev
codenamev / color_guess.rb
Created October 11, 2019 15:42
A color guessing game in Ruby on the Raspberry Pi
#!/usr/bin/env ruby
require "rpi_gpio"
# Set up a color table in Hexadecimal
COLOR = [
0xFF0000, # red
0x00FF00, # green
0x0000FF, # blue
0xFFFF00, # yellow
@codenamev
codenamev / breathing_led.rb
Created September 27, 2019 21:11
Make an LED breath, Ruby style.
#!/usr/bin/env ruby
require "rpi_gpio"
# Set #18 as LED pin
LED_PIN = 18
puts "========================================"
puts "| Breath LED |"
puts "| ------------------------------ |"
@codenamev
codenamev / eight_leds.rb
Last active September 17, 2019 18:00
Flow LED effect using a Raspberry Pi and Ruby
#!/usr/bin/env ruby
require "rpi_gpio"
LED_PINS = [17, 18, 27, 22, 23, 24, 25, 4]
puts "========================================"
puts "| 8 LEDs |"
puts "| ------------------------------ |"
puts "| LED0 connect to GPIO0 |"
@codenamev
codenamev / button_control_led.rb
Last active December 28, 2022 10:20
Control an LED with a button using Ruby on a Raspberry Pi
#!/usr/bin/env ruby
# Original source: https://github.com/codenamev/ruby-pi/blob/master/button_control_led.rb
require "rpi_gpio"
# Set #17 as LED pin
LED_PIN_NUMBER = 17
# Set #18 as button pin
BUTTON_PIN_NUMBER = 18
@codenamev
codenamev / blink_led.rb
Created September 6, 2019 14:52
Blink an LED with a Raspberry Pi and Ruby
@codenamev
codenamev / performance_logging.rb
Created April 8, 2019 18:38
A custom Rails logger for only reporting completed requests with their timing
# frozen_string_literal: true
module Performance
LOGGER = ActiveSupport::TaggedLogging.new(Logger.new(Rails.root.join("log", "performance.log")))
class LogSubscriber < ActiveSupport::LogSubscriber
def logger
LOGGER
end
end
@codenamev
codenamev / custom-workflow.rb
Last active November 9, 2018 21:30
Custom git-reflow Workflow
# Use a pre-defined workflow
use "FlatMergeWorkflow"
# Do something before the `start` command
before :start do
say "Booya! Started this bad girl."
end
# Do something after the `deliver` command
after :deliver do
@codenamev
codenamev / v1_models.rb
Created January 11, 2018 13:46
Woofers Modelling
class User < ApplicationRecord
has_many :dogs
end
class Dog < ApplicationRecord
belongs_to :user
end