Skip to content

Instantly share code, notes, and snippets.

View vinniefranco's full-sized avatar
🏡
WFH

Vincent Franco vinniefranco

🏡
WFH
View GitHub Profile
Mix.install([
{:claudio, "~> 0.2"},
{:owl, "~> 0.12"}
])
defmodule Baud do
@moduledoc """
A coding agent in one file.
The whole thing is a loop:
# When Ruby initializes a program, it instantiates all objects.
#
# This fires your class definitions as if they were methods.
# To illustrate here's an example
class Neat
p 'I am called' # straight to stdout!
# You can dynamically define class constants!
%w(ONE TWO THREE).each_with_index { |const, index| const_set const, index+1 }
end
@vinniefranco
vinniefranco / binary.rb
Created October 30, 2013 08:21
A binary helper for bitwise operations. Outputs: base10, hex, and binary representation of register value. Inputs: Base10: Anything below 999 is read into "register" as a value. Binary: Accepts anything over a half bit. e.g. 0111, 101010, and 1111000, etc. Register can be altered by bit shifting through AND, OR, and XOR operations.
require 'readline'
class String
# colorization
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
def red
colorize(31)
" Quick array creation
nmap <leader>ta vF=l<Esc>:s/\%V\S\+/"&",/g<CR>A<BS><Esc>vF=2lgS[JJ:let @/ = ""<CR>
# Tiny ass Luhn CC Check
def valid_luhn_cc? cc
a = i = 0
cc.each_char { |c| ((i%2)==0)? a+=c.to_i : (c.to_i*2).divmod(10).each { |j| a+=j }; i+=1 }
a % 10 == 0
end
function collision_test( obj1, obj2 )
var is_colliding = false;
if ( obj1.x < obj2.x + obj2.w &&
obj1.x + obj1.w > obj2.x &&
obj1.y < obj2.y + obj2.h &&
obj1.y + obj1.h > obj2.y ) {
is_colliding = true;
}
return is_colliding;
}
// Shorter cleaner way to add methods to an object prototype. Thank you Crockford
Function.prototype.method = function ( name, func ) {
if (! this.prototype[name] ) { this.prototype[name] = func; return this; }
};
// And here's the ability to add multiple KVs to objects
Function.method( "methods", function ( obj ) {
if ( typeof obj !== "object" ) return;
for ( var key in obj ) {
if ( ! obj.hasOwnProperty( key ) ) continue;
this.method( key, obj[key] );
# Cool shit about Ruby
# Arrays
array1, array2 = %w{ x y z }, %w{ w y z }
array1 | array2 ###(Union) #=> ["x", "y", "z", "w"]
array1 & array2 ###(Intersect) #=> ["y", "z"]
array1 - array2 ###(Difference) #=> ["x"]
# Strings