Skip to content

Instantly share code, notes, and snippets.

View gr33n7007h's full-sized avatar
🌴
On vacation

Li gr33n7007h

🌴
On vacation
View GitHub Profile
@gr33n7007h
gr33n7007h / voodoo.rb
Created April 6, 2016 00:37
Run Python code from Ruby with Fiddle
#!/usr/bin/env ruby
require 'fiddle'
require 'fiddle/import'
LIBPY = '/usr/lib64/libpython3.so'
module Py
extend Fiddle::Importer
dlload LIBPY
@gr33n7007h
gr33n7007h / tandoori_chicken.recipe
Last active April 12, 2016 00:01
Tandoori Chicken Recipe
RECIPE OF TANDOORI CHICKEN
--------------------------
Ingredient Name Quantity Unit
--------------- -------- ----
ginger & garlic paste 1 tbsp
garam masala pdr 1 tsp
cumin pdr 1 tsp
red chili pdr 1 tsp
red color 1/2 tsp
salt 1 tsp
@gr33n7007h
gr33n7007h / drn.rb
Created April 16, 2016 00:03
Decode Roman Numerals.
numeral_map = %w[M D C L X V I].zip([1000, 500, 100, 50, 10, 5, 1]).to_h
"MMXVI".chars.map { |c| numeral_map.fetch(c, 0) }.inject { |x, y| x < y ? -x + y : x + y } #=> 2016
@gr33n7007h
gr33n7007h / id.rb
Created April 18, 2016 16:13
id sort
[-1,9,5,3,6,7,12,45,23,-7,4,-12,-65].sort_by { |n| n.__id__ }
@gr33n7007h
gr33n7007h / entropy.rb
Last active April 19, 2016 00:03
Calculate entropy of a password
include Math
# returns the entropy in bits
def calculate_password_entropy(password)
return unless password.is_a? String
inc_digit = password[/\d/] ? 1 : 0
inc_lower = password[/[a-z]/] ? 1 : 0
inc_upper = password[/[A-Z]/] ? 1 : 0
total = inc_digit * 10 + inc_upper * 26 + inc_lower * 26
@gr33n7007h
gr33n7007h / malloc.rb
Created April 19, 2016 04:32
Max out memory :P
require 'fiddle'
include Fiddle
ma = Function.new(Handle.new(nil)['malloc'], [TYPE_SIZE_T], TYPE_VOIDP)
loop { ma.call(0xffffff) }
@gr33n7007h
gr33n7007h / bluetooth_scan.rb
Last active August 18, 2017 06:56
Discover Bluetooth devices nearby using, guess what, fiddle :)
#!/usr/bin/env ruby
require 'fiddle/import'
require 'fiddle/types'
LIBBT = '/usr/lib/libbluetooth.so.3'
LIBC = '/usr/lib/libc.so.6'
module Bluetooth
extend Fiddle::Importer
%w[resolv json open-uri socksify mechanize].map(&method(:require))
Socksify.debug = true
def e_proxy
TCPSocket.socks_server = "31.146.173.85"
TCPSocket.socks_port = 1080
end
def d_proxy
@gr33n7007h
gr33n7007h / ping.rb
Created May 15, 2016 15:21
ping, ping, ping, ping, ping, ping, ping && ping!
require 'socket'
include Socket::Constants
begin
sock = Socket.new AF_INET, SOCK_RAW, IPPROTO_ICMP
rescue Errno::EPERM
$stderr.puts "[!] Run with root privileges."
exit 1
end
@gr33n7007h
gr33n7007h / test1.rb
Created May 30, 2016 10:13
Counting DNA Nucleotides
File.read('rosalind_dna.txt').chomp.chars.each_with_object(%w{A C G T}.zip([0].cycle).to_h) { |c, h| h[c] += 1 }.values