Skip to content

Instantly share code, notes, and snippets.

@BrentonEarl
BrentonEarl / basic_sinatra.rb
Last active August 29, 2015 14:02
To test the embedding of Gists in jekyll web site.
#!/usr/bin/env ruby
require 'sinatra'
class Application < Sinatra::Base
get '/' do
"Hello World"
end
get '/about' do
@BrentonEarl
BrentonEarl / is_float_or_integer.rb
Created December 6, 2014 00:29
Extends the string class to test if a string is an integer or if it is a float
class String
def is_float?
Float(self) != nil rescue false
end
def is_integer?
Integer(self) != nil rescue false
end
end
@BrentonEarl
BrentonEarl / Rakefile
Last active August 29, 2015 14:10 — forked from ream88/Rakefile
Minitest Rakefile with :test set to default
require 'rake/testtask'
Rake::TestTask.new do |t|
t.pattern = 'test/*_test.rb'
end
task(default: :test)
@BrentonEarl
BrentonEarl / Specific_Minitest_Test.txt
Last active August 29, 2015 14:10
Run specific Minitest Unit Test or Spec
Given unit tests are located in the test/ directory.
In Shell:
$ ruby test/test_test.rb --name name_of_test_method
-----------------------
Or for all in that spec, simply:
In Shell:
@BrentonEarl
BrentonEarl / Rakefile
Last active August 29, 2015 14:11 — forked from tarynsauer/Rakefile
Automatically creates unit test files using "rake generate:test NAME=test_name and puts them in the test/ directory
namespace :generate do
desc "Add new Unit Test file"
task :test do
unless ENV.has_key?('NAME')
raise "Must specify a unit test file name, e.g., rake generate:test NAME=test_name"
end
unit_test_path = "test/" + ENV['NAME'].downcase + "_test.rb"
@BrentonEarl
BrentonEarl / address.rb
Last active August 29, 2015 14:11
Ruby class that makes use of ruby 2.1's new Socket.getifaddrs
require 'socket'
require 'netaddr' # this is a gem
class Address
# Pull the ip address from the local machine
def initialize
@info = Socket.getifaddrs.find do |ifaddr|
(ifaddr.flags & Socket::IFF_BROADCAST).nonzero? &&
ifaddr.addr.afamily == Socket::AF_INET
@BrentonEarl
BrentonEarl / nmapper.rb
Last active August 29, 2015 14:11 — forked from kenichi/nmapper.rb
require 'sinatra/base'
require 'celluloid'
class Nmapper
include Celluloid
def nmap opts = ''
`nmap #{opts}`
end
end
#!/usr/bin/env python
import argparse, os, subprocess
parser = argparse.ArgumentParser()
parser.add_argument("directory", help="The repository directory - /var/lib/sbopkg/{SBo,SBo-git}/")
parser.add_argument("maintainer", help="Supply SlackBuilds maintainer in quotes")
args = parser.parse_args()
for root, dirs, files in os.walk(args.directory):
@BrentonEarl
BrentonEarl / sbo_search_deps.py
Created July 11, 2016 01:56
Search for all SlackBuilds related to or that contain the keyword as a dependency.
#!/usr/bin/env python
import argparse, os, subprocess
parser = argparse.ArgumentParser()
parser.add_argument("directory", help="The repository directory - /var/lib/sbopkg/{SBo,SBo-git}/")
parser.add_argument("requires", help="Search SlackBuilds for a dependency or related SlackBuild")
args = parser.parse_args()
for root, dirs, files in os.walk(args.directory):
@BrentonEarl
BrentonEarl / whatismyip.rb
Last active July 12, 2016 15:33
Makes use of ruby nokogiri to get your public ip by scrapingf duckduckgo.com. Writes results to /tmp and prints it out.
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
page = Nokogiri::HTML(open("https://duckduckgo.com/html/?q=what%20is%20my%20ip", proxy: ""))
@text = page.css('div#zero_click_abstract')[0].text.strip
open('/tmp/whatismyip', 'w') do |f|