Skip to content

Instantly share code, notes, and snippets.

@AlessandroMinali
AlessandroMinali / helpx.rb
Created Jul 4, 2020
Quickly scan all of helpx for jobs.
View helpx.rb
require 'capybara/poltergeist'
session = Capybara::Session.new(:poltergeist)
puts "Search for: "
input = gets.chomp
[1,2,3,4,5,9].each do |i|
session.visit(
"https://www.helpx.net/hostlist.asp?search=#{input}&network=#{i}"
)
@AlessandroMinali
AlessandroMinali / etrex.rb
Created Jul 4, 2020
Split gpx file to fit on etrex devices
View etrex.rb
require 'nokogiri'
MAX = 10_000
BOTTOM = <<-STRING
</trkseg>
</trk>
</gpx>
STRING
@AlessandroMinali
AlessandroMinali / sun.rb
Created Jul 4, 2020
Calculate Sun Rise and Set times based. USAGE: ruby sun.rb <lat> <lon>
View sun.rb
# reference: https://en.wikipedia.org/wiki/Sunrise_equation#Complete_calculation_on_Earth
require 'date'
def rad(deg)
deg * Math::PI / 180.0
end
def deg(rad)
rad * 180.0 / Math::PI
end
@AlessandroMinali
AlessandroMinali / kanji.rb
Created Jul 4, 2020
Generate Anki Cards for all Kyōiku Kanji
View kanji.rb
require 'open-uri'
require 'nokogiri'
page = Nokogiri::HTML(URI.open(URI.encode("https://en.wikipedia.org/wiki/Kyōiku_kanji")))
kanji = page.css('span[title="Japanese language text"]').map &:text
third = kanji[240...440]
fourth = kanji[440...640]
@AlessandroMinali
AlessandroMinali / v2a.rb
Last active Jan 14, 2019
USAGE: v2a <file name>
View v2a.rb
#!/usr/bin/env ruby
if `which ffmpeg`.empty?
`brew install ffmpeg`
end
if ARGV[0].nil?
puts "Please specify a file."
exit
end
@AlessandroMinali
AlessandroMinali / split-mp4.rb
Created Nov 12, 2018
USAGE: split <file name> <number of sections>
View split-mp4.rb
#!/usr/bin/env ruby
unless system('which ffmpeg')
`brew install ffmpeg`
end
fname = ARGV[0]
seconds = `ffprobe -i #{fname} -show_entries format=duration -v quiet -of csv="p=0"`.to_f
times = ARGV[1]&.to_i || 3
`ffmpeg -i #{fname} -c copy -reset_timestamps 1 -f segment -segment_time #{(seconds/times).ceil} #{fname.chomp(".mp4")}_%02d.mp4`
View time_periods.rb
require 'date'
def days_in_month(year, month)
Date.new(year, month, -1).day
end
def end_of_day(time)
Time.new(
time.year,
time.month,
View git-fixup
#!/bin/sh
echo "Time to FIX IT"
git reset HEAD~1 --soft
git commit --amend --no-edit
@AlessandroMinali
AlessandroMinali / global.css
Last active Aug 23, 2018
Global stylesheet to block annoying shit on the web
View global.css
/* ROCK PAPER SHOTGUN */
div[class^="sp_message_container"] {
display: none !important;
}
div[class^="sp_veil"] {
display: none !important;
}
body.ads-enabled {
View quickstart-rom.rb
require 'sqlite3'
require 'rom'
require 'rom-sql'
class Item
attr_reader :id, :name
def initialize(attributes)
@id, @name = attributes.values_at(:id, :name)
end
end
class ItemsMapper < ROM::Mapper
You can’t perform that action at this time.