Skip to content

Instantly share code, notes, and snippets.

@cabron
cabron / masseffect.user.js
Last active December 11, 2015 20:29
ME3 Manifest Percentages and Character Builds
// ==UserScript==
// @name ME3 Manifest Percentages
// @namespace frostwyrm
// @include http://social.bioware.com/n7hq/home/inventory/?name=*&platform=*
// @include http://social.bioware.com/n7hq/home/characters/?name=*&platform=*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js
// ==/UserScript==
var percentageize = function (type) {
var denom = 0;
@cabron
cabron / flags.rb
Created October 26, 2012 12:15
Ruby: flag printer
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
COLOR_SOURCE_VALUES = 256
COLOR_TARGET_VALUES = 5
COLOR_DIVIDE = COLOR_SOURCE_VALUES / COLOR_TARGET_VALUES
TERM_COLOR_BASE = 16
def rgb_to_xterm(r, g, b) # part of grosser.it/2011/09/16/ruby-converting-html-colors-24bit-to-xtermterminal-colors/
@cabron
cabron / rpn.rb
Created July 9, 2012 15:42
/r/dailyprogrammer #73 intermediate
#!/usr/bin/env ruby
class RPNError < ArgumentError
def initialize sym, stack
args = stack.reverse.map.with_index {|el, i|
"#{el}.#{sym} (#{i} for #{el.method(sym).arity})"
}.join(', ')
super "wrong number of arguments: #{args}"
end
end
@cabron
cabron / ansi_seq.rb
Created May 15, 2012 16:27
ANSI Escape Sequences
class String
def seq
gsub(%r{
%% |
% (?<bg> B )? (?<sgr> black|red|green|yellow|blue|magenta|cyan|white|[0bu!_]|clr ) |
% (?<n1> \d+ )? (?<c> [\^v><\|\-!fb]<? ) (?<n2> \d+ )?
}x) {
match, bg, sgr, n1, c, n2 = *$~
if sgr #Select Graphic Rendition (reset, bold, underline, negative, colors) TODO: xterm colors
@cabron
cabron / xtea.rb
Created November 12, 2011 20:41
Simple implementation of XTEA in Ruby 1.8.7
class XTEA
attr_reader :key, :key_o
MASK = 0xFFFFFFFF
DELTA = 0x9E3779B9
def initialize(key=rand(2**128), n=32)
@key_o = key
@n = n
require 'net/http'
$page = Regexp.new(%{<em>([0-9]+)</em></span></a></li><li><a href="[^"]+"><span><em>nast})
$dodany = %{dodany przez <a .+>%s</a>[\\s]+.*z domeny: <a href="([^"]+)"}
user = ['rtoip7', 'reddigg']
def kazda_strona w, url
i = s = 1
while i <= s
require 'net/http'
require 'json'
require 'date'
Net::HTTP.start('www.reddit.com') do |re|
1000.times do |i|
Net::HTTP.get(URI.parse 'http://www.wykop.pl/strona/'+i.to_s).scan(/span title="([^"]+)".+[\s]+z <cite><a href="([^"]+)/).each {|time, url|
data = JSON.parse(re.get('/api/info.json?url='+url).body)['data']['children'].sort {|a, b| a['data']['created'] <=> b['data']['created'] }.first
puts data['data']['title'], data['data']['url'], DateTime.strptime(time, '%Y-%m-%d %T').to_time - Time.at(data['data']['created']).getlocal("+02:00") - (Time.now.dst? ? 7200 : 3600) if data
sleep 2
format ELF executable
entry _start
stdout = 0
stdin = 1
sys_exit = 1
sys_fork = 2
sys_read = 3
sys_write = 4
sys_waitpid = 7
require 'net/http'
url = URI.parse('http://www.wykop.pl')
Net::HTTP.start(url.host, url.port) {|http|
http.get('/ranking').body.scan(/dodane przez ([^\"]+)/).each {|nick| open(nick.first + ".jpg", 'wb') {|f|
f.write Net::HTTP.get URI.parse http.get('/ludzie/' + nick.first).body[/url.+\)/][4..-2]
} }
}