Skip to content

Instantly share code, notes, and snippets.

View oinak's full-sized avatar

Fernando Martínez oinak

View GitHub Profile
@mmontalvo
mmontalvo / Utilities
Last active September 24, 2015 04:57
List of useful commands
# To uninstall ALL gems
for i in `gem list --no-versions`; do gem uninstall -aIx $i; done
@oinak
oinak / jazzfonica.rb
Created July 3, 2011 10:10 — forked from christos/jazzfonica.rb
jazzfonica
#!/usr/bin/env ruby
# jazzfonica.rb for Mac OS X
# Scans the visible networks for JAZZTEL_XXXX or WLAN_XXXX and calculates the password
# Ported from PHP example at http://kz.ath.cx/wlan/codigo.txt
# Download and execute with ruby (e.g. ruby jazzfonica.rb) from a Terminal
require 'digest/md5'
messages = []
unless !File.exists?('/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport')
@oinak
oinak / vpn.rb
Created November 18, 2011 07:53
Configure custom vpn's
#!/usr/bin/env ruby
require "rubygems" # ruby1.9 doesn't "require" it though
require "thor"
# The program takes different commands as in git thing style.
# At the moment it list avaiable/enable VPN's or sets them.
#
# Author:: Fernando Martínez (mailto:[email protected])
# Copyright:: Copyright (c) 2010 LCIbérica SL
# License:: Distributes under the same terms as Ruby
@txus
txus / versionable.rb
Created October 16, 2012 20:49
Mindfuck of the day: versionable Ruby objects
# Note, some syntax inspired from that persistent data structures library for Ruby, Hamster??
# Scroll to the bottom to see it in action.
module Versioned
def self.included(base)
base.class_eval do
def self.new(*args)
new_mutable(*args).freeze
end
@funny-falcon
funny-falcon / changes.md
Last active August 15, 2024 15:13
Performace patch for ruby-1.9.3-p327

Changes:

  • this version includes backport of Greg Price's patch for speedup startup http://bugs.ruby-lang.org/issues/7158 .

    ruby-core prefers his way to do thing, so that I abandon cached-lp and sorted-lf patches of mine.

  • this version integrates 'array as queue' patch, which improves performance when push/shift pattern is heavily used on Array.

    This patch is accepted into trunk for Ruby 2.0 and last possible bug is found by Yui Naruse. It is used in production* for a couple of months without issues even with this bug.

@peterc
peterc / methods_returning.rb
Last active October 29, 2023 03:10
Object#methods_returning - to work out which method on an object returns what we want
require 'stringio'
require 'timeout'
class Object
def methods_returning(expected, *args, &blk)
old_stdout = $>
$> = StringIO.new
methods.select do |meth|
Timeout::timeout(1) { dup.public_send(meth, *args, &blk) == expected rescue false } rescue false

I highly suspect that the RSpec core team all use black backgrounds in their terminals because sometimes the colors aren’t so nice on my white terminal

I certainly use a black background. I'm not sure about the other RSpec core folks. Regardless, if there are some color changes we can make that would make output look good on a larger variety of backgrounds, we'll certainly consider that (do you have some suggested changes?). In the meantime, the colors are configurable, so you can change the colors to fit your preferences on your machine. First, create a file at

@albertstill
albertstill / enigma_machine.rb
Last active February 25, 2021 18:46
Understand how the Enigma machine works with 30 lines of Ruby
Plugboard = Hash[*('A'..'Z').to_a.sample(20)]
Plugboard.merge!(Plugboard.invert)
Plugboard.default_proc = proc { |_, key| key }
def build_a_rotor
Hash[('A'..'Z').zip(('A'..'Z').to_a.shuffle)]
end
ROTOR_1, ROTOR_2, ROTOR_3 = build_a_rotor, build_a_rotor, build_a_rotor
@ferblape
ferblape / factories.rb
Created April 13, 2016 18:25
Custom factory
module Factories
def new_user(attrs = {})
attrs[:email] ||= "[email protected]"
attrs[:password] ||= "foo123456"
attrs[:password_confirmation] ||= attrs[:password]
User.new(attrs)
end
def create_user(attrs = {})
new_user(attrs).save!
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"