Skip to content

Instantly share code, notes, and snippets.

View jah2488's full-sized avatar

Justin Herrick jah2488

View GitHub Profile
@jah2488
jah2488 / projeulp1.rb
Created February 29, 2012 06:12
Project Euler Problem 1
i = 0
nums = []
while i < 1000
nums << i if i%3 == 0 or if i%5 == 0
i+=1
end
nums.inject{|sum,i| sum + i }
//=====================================================================================
// Program Name: TicTacToe
// Author: Gonzales Cenelia
// Website: www.ai-programming.com
//
// This is a complete Tictactoe game, it include many functionalities, you can play games
// against another human, you can play against the computer, you can also even let the computer
// play against itself. The A.I is very good, actualy it is unbeatable, the most you can do is to
// draw the games. Also, the game include statistics (number of win, draw an lost games) for the
@jah2488
jah2488 / rainbow-print.clj
Created June 21, 2012 20:42
Print Any message you want in beautiful colors!
(defn rainbow-print [msg]
(let [colors ["31m" "32m" "33m" "34m" "35m" "36m" "37m"]
costr (fn [color msg] (str "\033[" color msg "\033[m"))]
(println
(str (apply str (map #(costr (rand-nth colors) %) (clojure.string/split msg #"\d*")))))))
User = Struct.new :username, :password
user = User.new "Josh", "super"
user.instance_variables # => []
user.public_methods(false) # => [:username, :username=, :password, :password=]
" Ge off my lawn
nnoremap <Left> :echoe "Use h"<CR>
nnoremap <Right> :echoe "Use l"<CR>
nnoremap <Up> :echoe "Use k"<CR>
nnoremap <Down> :echoe "Use j"<CR>
@jah2488
jah2488 / StubbyMock.rb
Created October 9, 2012 01:47
Quick and Dirty "Mock" and "Stub" functionality in ruby. Could be used for making Independent mock files or for NullObjects
require 'rubygems'
require 'rspec'
module FakeIt
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def mocks(class_name)
class_name.instance_methods(false).map { |method_name| define_method(method_name) { |*args| } }
(declare rank-board)
(defn best-move [board player]
(let [moves (empty-cells board)
scores (zipmap moves (map #(rank-board (update-board board % player) player 1) moves))
best-score (reduce max (vals scores))
best-moves (filter #(= (scores %) best-score) moves)]
(rand-nth best-moves)))
(defn rank-board
@jah2488
jah2488 / style.rb
Created December 5, 2012 22:16
I do the same thing.
def self.by_name(query)
response = [""]
names = query.split
names.each do |value|
response[0] += names.last.equal?(value) ? "lower(name) LIKE '%'||?||'%'" : "lower(name) LIKE '%'||?||'%' AND "
response << value.downcase
end
find(:all, :conditions => response)
end
#!/usr/bin/env python
#===========================================================================================================================================
# ---- Productivity Calculator for Erepublik Beta and V1 ----
## Created by me
#
# Beta 0.3.5 -- October 25th 2008
#
##Notes
#
## Fatal Occurs during Windows EXE. Something wrong with the SHELVE Module
@jah2488
jah2488 / changer.rb
Last active December 12, 2015 02:29
Coin Changer kata in ruby, attempting to remove all assignments
def changer(change)
[25,10,5,1].map do |coin|
rem = change / coin
change -= (rem * coin)
[coin] * rem
end.flatten
end
# Invocations = 5
# Assignments = 2 (or 3 if you count the Array Literal)