Skip to content

Instantly share code, notes, and snippets.

View 0xradical's full-sized avatar

Thiago Brandão 0xradical

View GitHub Profile
data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script>
@0xradical
0xradical / github_ruby_coloring.rb
Created February 7, 2013 17:28
Testing Github colors for Ruby
require "test"
CONSTANT = 777
# Sample comment
class Module::Class
include Testcase
render :action => 'foo'
def foo(parameter)
require 'ap'
require 'ripper'
CLASS_TEXT = "class A; end; class B; end"
CLASS_SEXP = Ripper.sexp(CLASS_TEXT)
BIG_TEXT = "class A; def a; @a = b; end; def b; @d = a; @e = a; end; end; module B; def b; end; end"
BIG_SEXP = Ripper.sexp(BIG_TEXT)
@0xradical
0xradical / phone_query.rb
Last active December 14, 2015 07:29
Script to query phones
class PhoneQuery
def initialize(input)
@input = input
end
def to_sql
query = Phone.where('(1 = 0)').to_sql
return query if @input.blank?
@0xradical
0xradical / reset_mac_password.txt
Created March 4, 2013 04:26
reset_mac_password.txt
Boot into single user mode (press Command-S at power on)
Type fsck -fy
Type mount -uw /
Type launchctl load /System/Library/LaunchDaemons/com.apple.DirectoryServices.plist
Type dscl . -passwd /Users/username password, replacing username with the targeted user and password with the desired password.
Reboot
@0xradical
0xradical / first_with.rb
Last active December 14, 2015 16:49
Find first that matches block
module QueryingWithBlock
def first_with(&block)
find_each do |record|
return record if block.call(record)
end
end
end
# ActiveRecord::Relation includes QueryingWithBlock
ActiveRecord::Relation.class_eval do
@0xradical
0xradical / test_encoding.rb
Last active December 14, 2015 17:09
Test string against every encoding present in Encoding.aliases.values
test_string = 'Informação'
Encoding.aliases.values.uniq.each do |encoding|
begin
puts "In #{encoding}: #{test_string.clone.force_encoding(encoding)}"
rescue
puts "Barfed for #{encoding}"
end
end
@0xradical
0xradical / without_nasty_chain.rb
Last active December 14, 2015 19:38
POC - wicked_pdf and remotipart without nasty alias_method_chain
# wicked pdf
module WickedPdfHelper
def render(options = nil, *args, &block)
if options.is_a?(Hash) && options.has_key?(:pdf)
puts 'do pdf stuff'
end
super
end
end
@0xradical
0xradical / fizz_buzz.rb
Last active December 15, 2015 02:59
FizzBuzz in Ruby
1.upto(100).each do |number|
if number % 3 != 0 && number % 5 != 0
puts "#{number}: #{number}"
else
puts "#{number}: #{number % 3 == 0 ? 'Fizz' : '' }#{number % 5 == 0 ? 'Buzz' : ''}"
end
end
@0xradical
0xradical / mysql.rb
Created March 25, 2013 17:08
Mysql functions
class MysqlQuery
def initialize
@query = ""
end
end