Skip to content

Instantly share code, notes, and snippets.

View xoebus's full-sized avatar
🤖
beep beep

Christopher Brown xoebus

🤖
beep beep
  • San Francisco, CA
View GitHub Profile
@xoebus
xoebus / terminal-width.rb
Created September 6, 2010 14:17
A snippet of code from HIRB to detect the terminal width.
def detect_terminal_size
if (ENV['COLUMNS'] =~ /^\d+$/) && (ENV['LINES'] =~ /^\d+$/)
[ENV['COLUMNS'].to_i, ENV['LINES'].to_i]
elsif (RUBY_PLATFORM =~ /java/ || !STDIN.tty?) && command_exists?('tput')
[`tput cols`.to_i, `tput lines`.to_i]
else
command_exists?('stty') ? `stty size`.scan(/\d+/).map { |s| s.to_i }.reverse : nil
end
rescue
nil
@xoebus
xoebus / ask.rb
Created September 15, 2010 12:06
def ask(question, default=nil, valid = /.*/, multiline=false)
output = question
output << " [#{default}]" unless default.nil?
output << " (Optional)" if valid =~ ""
output << ": "
puts output
matches = false
answer = default
@xoebus
xoebus / ask.rb
Created September 15, 2010 14:51
def ask(question, default=nil, valid = /.*/, multiline=false)
output = question
output << " [#{default}]" unless default.nil?
output << " (Optional)" if valid =~ ""
output << ": "
puts output
matches = false
answer = default
@xoebus
xoebus / Deadlines.txt
Created October 16, 2010 14:37
Coursework for Semester 1
Individual Practical
====================
Part 1 - 21/10/10
Operating Systems
=================
Practical - 12/11/10
Essay - 26/11/10
Algorithms & Data Structures
*Main> rmChar 'a' "Hallo"
"Hllo"
Is given by:
characterDrop a x = (a /= x)
rmChar :: Char -> String -> String
rmChar a xs = filter (characterDrop a) xs
#include <stdio.h>
#include <string.h>
char* strrev(char* start, char* end)
{
char *i = start;
char *j = end;
while (i < j)
{
TEX_FILES = FileList["*.tex", "figures/*", "*.bib", "*.cls"]
MAIN = "thesis" # name of main file without .tex suffix
MAIN_TEX = "#{MAIN}.tex"
OUT_PDF = "#{MAIN}.pdf"
file OUT_PDF => TEX_FILES do
%x{pdflatex -interaction=batchmode #{MAIN_TEX} >/dev/null 2>&1}
%x{makeindex #{MAIN} >/dev/null 2>&1}
%x{bibtex #{MAIN} >/dev/null 2>&1}
%x{pdflatex -interaction=batchmode #{MAIN_TEX} >/dev/null 2>&1}
@xoebus
xoebus / .gitconfig
Created November 14, 2010 01:10
My git configuration
[user]
name = Chris Brown
email = cb@tardis.ed.ac.uk
signingkey = D5E60FB1
[github]
user = xoebus
token = [REDACTED]
[alias]
st = status
ci = commit
@xoebus
xoebus / steam.rb
Created December 3, 2010 05:43
Gets playtime of a profile's games.
require 'nibbler'
require 'open-uri'
class SteamProfile < Nibbler
elements 'div.gameListRowItem' => :games do
element 'h4' => :title
element 'h5' => :playtime, :with => lambda { |time|
time.inner_text.strip.split(" ").first.to_f
}
end
@xoebus
xoebus / nibble.rb
Last active July 30, 2023 11:18
Some code to grab Minecraft codes off reddit.
require 'nibbler'
require 'open-uri'
CODE_RE = /[A-Za-z1-9]{4}-[A-Za-z1-9]{4}-[A-Za-z1-9]{4}/
class String
[:gray, :red, :green, :yellow, :blue, :purple, :cyan, :white].each_with_index do |color, i|
define_method color do "\033[1;#{30+i}m#{self}\033[0m" end
define_method :"#{color}ish" do "\033[0;#{30+i}m#{self}\033[0m" end
end