This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Mix.install([ | |
| {:claudio, "~> 0.2"}, | |
| {:owl, "~> 0.12"} | |
| ]) | |
| defmodule Baud do | |
| @moduledoc """ | |
| A coding agent in one file. | |
| The whole thing is a loop: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'readline' | |
| class String | |
| # colorization | |
| def colorize(color_code) | |
| "\e[#{color_code}m#{self}\e[0m" | |
| end | |
| def red | |
| colorize(31) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " Quick array creation | |
| nmap <leader>ta vF=l<Esc>:s/\%V\S\+/"&",/g<CR>A<BS><Esc>vF=2lgS[JJ:let @/ = ""<CR> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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] ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |