Skip to content

Instantly share code, notes, and snippets.

View WA9ACE's full-sized avatar
🏍️
🛣🚐 💨 Exploring

Caleb Albritton WA9ACE

🏍️
🛣🚐 💨 Exploring
View GitHub Profile
@WA9ACE
WA9ACE / gist:0dd9764786ecbdd7c564
Created February 12, 2015 00:24
Quick and dirty, not tested.
def nearby_az(string)
raise ArgumentError if !string.include? 'a'
a_idx = string.index("a")
string[a_idx + 1] == "z" || string[a_idx + 2] == "z" || string[a_idx +3] == "z"
end
@WA9ACE
WA9ACE / fps.js
Created October 15, 2014 21:53
Simple way to calculate the FPS when using requestAnimationFrame
window.onload = function() {
var lastCalledTime;
var counter = 0;
var fpsArray = [];
function update(timestamp) {
var fps;
if (!lastCalledTime) {
lastCalledTime = new Date().getTime();
@WA9ACE
WA9ACE / uberbot.conf
Created September 4, 2014 03:59
/etc/init/uberbot.conf Ruby Upstart script
description "Ruby App"
start on net-device-up IFACE=eth0
stop on shutdown
respawn
setuid user
setgid user
@WA9ACE
WA9ACE / eventmapper.rb
Created June 2, 2014 17:00
Event Library Tutorial
module EventMapper
def on(event, &block)
if @events.nil?
@events = { event => [block] }
elsif @events[event].nil?
@events[event] = [block]
else
@events[event] << block
end
end
@WA9ACE
WA9ACE / ICEBrain.h
Last active August 29, 2015 14:01
Objective-C with comments to point out semantic syntax differences with Ruby : Part 1
//
// ICEBrain.h
//
#import <Foundation/Foundation.h>
@interface ICEBrain : NSObject
@property (nonatomic) NSString *someProperty;
Maybe = function(value) {
var Nothing = {};
var Something = function(value) {
return function() {
return value;
};
};
if (typeof value === 'undefined' || value === null)
@WA9ACE
WA9ACE / spider.js
Last active April 27, 2016 07:16
Node.js Web Crawler using Request and Cheerio
var request = require('request');
var cheerio = require('cheerio');
var fs = require('fs');
var data = fs.createWriteStream('data.txt', {'flags': 'a'});
var urlsToCrawl = [];
var spider = function(url) {
var index = urlsToCrawl.indexOf(url);
@WA9ACE
WA9ACE / card_trick.rb
Last active December 22, 2015 21:19
13 cut card trick
cards = [*'2'..'10', 'J', 'Q', 'K', 'A']
suits = ['C', 'D', 'H', 'S']
deck = cards.product(suits).map(&:join)
13.times do
r = rand(1..52)
cut = deck.pop(r)
deck.unshift(cut).flatten!
end
@WA9ACE
WA9ACE / price_check.rb
Last active December 12, 2015 05:49
Bitcoin Gem price checker with notifications.
require 'nokogiri'
require 'open-uri'
require 'terminal-notifier'
title = 'Bitcoin Gem'
activate = 'com.googlecode.iterm2'
current_price = 0
while 1
@WA9ACE
WA9ACE / replacer.rb
Last active December 10, 2015 21:38
Text Replacer
#!/usr/bin/env ruby
content = ''
Dir.glob(['*.php', '*.html', '*.htm', '*.js', '*.css']).each_with_index do |filename, index|
file = File.read(filename)
# Ruby assumes all things created are UTF-8 which is false and will stop executing
# when if finds something that isn't. Hence this.
file.encode!('UTF-16', :undef => :replace, :invalid => :replace, :replace => "")