Colored for chat colors
gem install colored
It has many comments since I tried to explain what is going on for less-experienced Ruby people.
| # Explanation of attr_* to Noxn | |
| # Let's start with an example class using attr_acessor: | |
| class Klass | |
| attr_acessor :variable | |
| def initialize(content) | |
| @variable = content | |
| end | |
| end |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!-- Do not edit this file, it will be overwritten on install. | |
| Copy the file to $HOME/.config/openbox/ instead. --> | |
| <openbox_config xmlns="http://openbox.org/3.4/rc"> | |
| <resistance> | |
| <strength>20</strength> | |
| <screen_edge_strength>30</screen_edge_strength> | |
| </resistance> | |
| <focus> | |
| <focusNew>yes</focusNew> |
| # not so insane | |
| class Fixnum | |
| def fizzbuzz | |
| buffer = '' | |
| buffer += 'Fizz' if self % 3 == 0 | |
| buffer += 'Buzz' if self % 5 == 0 | |
| buffer.empty? ? self : buffer | |
| end | |
| end |
| require 'benchmark' | |
| require 'redis' | |
| require 'yaml' | |
| require 'json' | |
| N = 100000 | |
| Benchmark.bm do |r| | |
| @redis = Redis.new | |
| @serialize_me = [1,2,3,4,5] |
| #!/usr/bin/env ruby | |
| puts "8#{'='*STDIN.read[/\d/].to_i}D" | |
| # $ uptime | |
| # 23:42 up 56 days, 15:19, 2 users, load averages: 0.34 0.41 0.41 | |
| # $ uptime | ruby epenis.rb | |
| # 8========================================================D |
| #!/bin/bash | |
| # | |
| # Launches sshuttle if you're on an untrusted network, currently only available on OS X. | |
| # Patches for Linux support welcome! | |
| # | |
| # sshutle: Transparent proxy server that works as a poor # man's VPN. | |
| # Forwards over ssh. Doesn't require admin. Works with Linux and MacOS. Supports DNS tunneling. | |
| # https://github.com/apenwarr/sshuttle | |
| # | |
| # Dependencies |
| # requires root permissions in /usr/bin/ | |
| star = String.new | |
| 8.times { star += "*" } | |
| Star = "\n#{star * 3}\n" | |
| def newblock string | |
| puts "\n#{Star}#{string}#{Star}\n" | |
| end |
| if defined? ActiveRecord | |
| def explain(query) | |
| query = query.to_sql if query.is_a?(ActiveRecord::Relation) | |
| ActiveRecord::Base.connection | |
| .execute("EXPLAIN ANALYZE #{query}") | |
| .to_a | |
| .each { |hash| puts hash["QUERY PLAN"] } | |
| nil |
| require "net/https" | |
| require "uri" | |
| require 'json' | |
| def request(url) | |
| uri = URI.parse(url) | |
| http = Net::HTTP.new(uri.host, uri.port) | |
| http.use_ssl = true | |
| http.verify_mode = OpenSSL::SSL::VERIFY_NONE |