This file contains 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
#used ruby version 2.0.0, probably works on 1.9.x as well, may not work on 1.8.x | |
require 'mechanize' | |
mech = Mechanize.new | |
page = mech.get("http://www.europarl.europa.eu/meps/en/full-list.html?filter=all&leg=") | |
mep_links = [] | |
page.links.each do |x| #a Mechanize::Page object provides us with all the links on the downloaded page |
This file contains 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
#LD28 entry by Takemikazuchi545 | |
require 'gosu' | |
require 'chunky_png' | |
require 'pp' | |
def tile_diff(x, y, zoom_level) | |
x += $camera_offset_x | |
y += $camera_offset_y | |
new_x = ((x - y) * Tile::WIDTH/2 * zoom_level) + 1920/2 | |
new_y = ((x + y) * Tile::HEIGHT/2 * zoom_level) + 1080/2 |
This file contains 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 'gosu' | |
class CellMap | |
include Enumerable | |
def initialize(x, y, chance_to_start_alive) | |
@map = Array.new | |
a = Random.new() | |
x.times do | |
column = Array.new(y) |
This file contains 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
def quicksort(array, first = true) | |
if first == true | |
# if this is the first time quicksort is invoked | |
# we have to de-reference the array, as we use the | |
# destructive method delete_at | |
array = array.dup | |
end | |
if array.size <= 1 |
This file contains 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
class Brand < ActiveRecord::Base | |
has_many :products | |
validates :name, presence: true | |
has_attached_file :logo, :styles => { :medium => "300x300>", :thumb => "100x100>" } | |
has_attached_file :header, styles: {medium: "x200"} | |
end |
This file contains 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
class Array | |
def is_sorted? | |
self.each_with_index do |curr_element, index| | |
next_element = self[index + 1] | |
unless next_element == nil || curr_element < next_element | |
return false | |
end | |
end | |
return true |
This file contains 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
# builds an array of lower/upper case alphabet characters | |
# and returns a random character from that | |
def rand_char | |
chars = (('a'..'z').to_a + | |
('A'..'Z').to_a + | |
(0..9).to_a ) | |
chars[rand(chars.length)].to_s | |
end | |
# Takes a string str and returns it with random characters |
This file contains 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
# Takes a set of characters and generates permutations, starting at 2 characters, | |
# and checks them against the linux word list. If there are any matches, it adds | |
# new characters to those from the permutation set, dropping permutations with no | |
# match. If any permutation fully matches a word, it adds that to the word list. | |
permutations = %w[i w e r].shuffle | |
starting_chars = [] | |
def permutation_compliments(starting_str, permutations) |
This file contains 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
# -*- coding: utf-8 -*- | |
# Welcome to the Chinese Support Add-on's field edition ruleset. | |
# Here, you can tweak the note editor helper's behavior to your liking. | |
# | |
# If you messed things up, you can safely delete file | |
# addons/chinese/edit_behavior.py from your Anki directory. | |
# It will be recreated the next time you restart Anki. | |
# | |
# You can read about all available functions at: | |
# https://github.com/ttempe/chinese-support-addon/wiki/Edit-behavior |
This file contains 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
# This extends the Array class with a special method called each_[insert integer here] | |
# For example, each_1 invokes the block for every single element in an array, each_2 invokes the block for | |
# each pair, each_3 for triples, so on and so forth. This is a purely educational example of using | |
# metaprogramming to replicate functionality using patterns rather hard coding a new method for each | |
# new case you need to account for. | |
class Array | |
def method_missing(meth, *args, &block) | |
if meth.to_s =~ /^each_(\d+)$/ | |
run_each_by_num($1.to_i, &block) |
OlderNewer