Skip to content

Instantly share code, notes, and snippets.

View bagilevi's full-sized avatar

Levente Bagi bagilevi

View GitHub Profile
@bagilevi
bagilevi / pushover_api_client.rb
Last active November 10, 2025 09:36
pushover_api_client.rb
require 'net/http'
require 'uri'
require 'json'
# Example usage:
#
# PushoverApiClient.new.send_message(
# title: "Error on website",
# message: "Database connection failed",
# priority: 1, # -2 lowest, -1 = low, 0 = normal, 1 = high (always generate sound and vibration), 2 = emergency (retried until acknowledged)
@bagilevi
bagilevi / .gitconfig
Created December 8, 2020 10:30
git config
[alias]
wip = for-each-ref --sort='authordate:iso8601' --format=' %(color:green)%(authordate:relative)%09%(color:white)%(refname:short)' refs/heads
@bagilevi
bagilevi / unlinkify.js
Last active November 25, 2018 12:43
Remove links from a wep page, to make it easier to copy text, e.g. when you want to use a translation tool. Works on sites that use jQuery, e.g. Wikipedia.
$('a').each(function(x, e) { $e = $(e); $e.replaceWith($('<span>').html($e.html()))});null
@bagilevi
bagilevi / genpass.rb
Created December 19, 2017 16:14
password generator
#!/usr/bin/env ruby
lens = Array(ARGV[0]&.to_i || [20, 16, 10, 8, 6])
lo = 'qwertuiopasdfghjkxcvbnm'.split('')
up = 'QWERTUPASDFGHJKLXCVBNM'.split('')
nu = '123456789'.split('')
si = '!@#$%^&*()-=+[]{};\'\\:"|,./<>?'.split('')
lens.each do |len|
@bagilevi
bagilevi / remove_node_modules.rb
Last active December 11, 2016 16:37
Remove all node_modules directories within a directory (Ruby)
#!/usr/bin/env ruby
# Remove all node_modules directories within a directory
base_dir = File.expand_path(ARGV[0])
# Boilerplate from: http://stackoverflow.com/questions/1154846/continuously-read-from-stdout-of-external-process-in-ruby#answer-1162850
require 'pty'
cmd = "find #{base_dir} -name node_modules"
begin
@bagilevi
bagilevi / volt_calculated_field.rb
Created April 25, 2015 05:24
Volt calculated field
class Person < Volt::Model
field :first_name
field :last_name
field :full_name
def initialize(*args)
super
-> {
self.full_name = [first_name, last_name].compact.join(' ')
}.watch!
@bagilevi
bagilevi / capybara_extras.rb
Created June 30, 2014 08:28
Capybara - following local redirects only
module CapybaraExtras
def browser
Capybara.current_session.driver.browser
end
def response
@response
end
@bagilevi
bagilevi / runnable_classes_as_methods.rb
Created February 6, 2014 18:04
Ruby mixin that makes runnable classes available as methods
require 'active_support/core_ext'
# Makes runnable classes available as methods.
#
# Example:
#
# class FirstClass
# include RunnableClassesAsMethods
# class AddNumbers
# def initialize(a, b); @a, @b = a, b end
@bagilevi
bagilevi / rename_all.rb
Created February 3, 2014 16:54
Rename files and file contents in a directory
#!/usr/bin/env ruby
require 'active_support/core_ext'
a, b = ARGV
NilClass.class_eval do
def each_line
end
end
@bagilevi
bagilevi / proc_instance_eval_experiment.rb
Created January 15, 2014 10:43
proc.call vs instance_eval(&proc)
def describe(&proc)
Object.new.instance_eval(&proc)
end
proc = ->(*args){
puts "Proc called:"
puts " self: #{self.inspect}"
puts " args: #{args.inspect}"
}