Skip to content

Instantly share code, notes, and snippets.

Avatar

Jan Dudek jdudek

View GitHub Profile
@jdudek
jdudek / Multi.php
Created Sep 15, 2010
Doctrine_Pager extension that handles multiple queries
View Multi.php
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
@jdudek
jdudek / user_spec.rb
Created Nov 24, 2010
Test validations in ActiveRecord
View user_spec.rb
require 'spec_helper'
module ActiveModel
class Errors
def error_names
@_error_names ||= { }
end
def add_with_save_names(attribute, message = nil, options = {})
message ||= :invalid
@jdudek
jdudek / first-f.txt
Created Dec 7, 2010
Random Polish names generator / Generator losowych nazwisk, lista losowych nazwisk
View first-f.txt
Anna
Maria
Katarzyna
Małgorzata
Agnieszka
Krystyna
Barbara
Ewa
Elżbieta
Zofia
@jdudek
jdudek / convert.rb
Created Jan 31, 2011
Convert Opera's .adr address book to CSV
View convert.rb
# ruby 1.9.2
require "csv"
File.open("contacts2.adr", "r") do |f|
contacts = []
f.read.split("#CONTACT").each do |entry|
unless entry.empty?
contact = {}
entry.each_line do |line|
@jdudek
jdudek / sessions_controller.rb
Created Mar 15, 2011
Session isolation in Capybara/Steak tests
View sessions_controller.rb
class SessionsController < ApplicationController
def create
session[:created] = true
render :text => "Session created"
end
def check
if session[:created]
render :text => "Session exists"
else
View deferred.html
<!DOCTYPE html>
<html>
<head>
<script src="jquery.js" type="text/javascript"></script>
<script src="deferred.js" type="text/javascript"></script>
</head>
<body></body>
</html>
View import.rb
csv = File.open("index.csv", "w")
Dir.glob("in/*").each_with_index do |path, i|
file = path.gsub("in/", "").gsub(/\.wav$/, "")
index = i + 1
difficulty = case file
when /^latwe/
1
when /^srednie/
View tags.rb
create_table "taggings", :force => true do |t|
t.integer "tag_id"
t.string "taggable_type", :default => ""
t.integer "taggable_id"
end
class Post
has_many :taggins, :polymorphic => true
def tags
View tags.rb
create_table "tags", :force => true do |t|
t.string "name", :default => ""
end
create_table "taggings", :force => true do |t|
t.integer "tag_id"
t.string "taggable_type", :default => ""
t.integer "taggable_id"
end
@jdudek
jdudek / game_api_test.rb
Created Sep 13, 2011
Testing REST API using BBQ
View game_api_test.rb
require File.dirname(__FILE__) + "/../test_helper"
class GameApiTest < Bbq::TestCase
background do
@admin = TestUser.new
@admin.roles(:admin)
@admin.prepare_game_data
@client = TestClient.new
@client.extend(TestClient::GameClient)
You can’t perform that action at this time.