Skip to content

Instantly share code, notes, and snippets.

View yoshikischmitz's full-sized avatar
🐳
Focusing

Yoshiki Schmitz yoshikischmitz

🐳
Focusing
View GitHub Profile
#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
#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
@yoshikischmitz
yoshikischmitz / Cellmap.rb
Last active January 1, 2016 02:09
Ruby implementation of a simple cellular automata simulator. Gosu is used just for drawing, the CellMap class doesn't have any gosu specific code so it's very portable. Following this tutorial: http://gamedevelopment.tutsplus.com/tutorials/cave-levels-cellular-automata--gamedev-9664
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)
@yoshikischmitz
yoshikischmitz / quicksort.rb
Last active January 1, 2016 23:08
Simple quicksort in Ruby, just as an exercise.
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
@yoshikischmitz
yoshikischmitz / brand.rb
Last active January 3, 2016 22:19
Order Management System Modes
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
@yoshikischmitz
yoshikischmitz / Bogosort.rb
Last active August 29, 2015 13:55
Bogosort
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
@yoshikischmitz
yoshikischmitz / splice_rand_chars.rb
Last active August 29, 2015 13:56
Splice random characters into a string
# 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
@yoshikischmitz
yoshikischmitz / chars_to_word.rb
Last active August 29, 2015 13:57
Ruby Word Finder
# 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)
@yoshikischmitz
yoshikischmitz / edit_behavior.py
Last active August 29, 2015 13:57
Customized edit_behavior.py for Annki Chinese Support Plugin. Pulls word usage examples from dict.cn
# -*- 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 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)