Skip to content

Instantly share code, notes, and snippets.

View FlaviuSim's full-sized avatar

Flaviu Simihaian FlaviuSim

View GitHub Profile
@FlaviuSim
FlaviuSim / iframe-position.html
Created April 4, 2011 17:30
Positioning an iframe's content
<html>
<head>
<style>
#my-div
{
width : 534px;
height : 850px;
overflow : hidden;
position : relative;
}
@FlaviuSim
FlaviuSim / gist:903001
Created April 5, 2011 04:05
bash script to convert directory structure to xml - by @sente
function indent() {
depth=$1
spacer=${2:" "}
for ((i=0;i<$depth;i++)); do
echo -ne " ";
done
}
function recurse() {
local name=$1
@FlaviuSim
FlaviuSim / watch
Created May 4, 2011 03:18
Python watch for modified files and run tests
#!/usr/bin/env python
"""
-Thanks to Shawn Milochik for this - saved for future reference
Run unit test suite every time a Python file
is modified.
Requires pyinotify:
https://github.com/seb-m/pyinotify
"""
def isAnagramOf(attempt, original):
# all the same case
attempt = attempt.strip()
if len(attempt) < 1: # only actual words
return False
attempt, original = attempt.lower(), original.lower()
for character in attempt:
position = original.find(character)
if (position == -1):
return False
@FlaviuSim
FlaviuSim / gist:1224087
Created September 17, 2011 16:10
factory_girl association recursion
# Question model - question.rb
class Question < ActiveRecord::Base
attr_accessible :text, :survey_id
belongs_to :survey
validates_presence_of :text, :survey
end
#Survey model - survey.rb
after_build do |q|
2.times { q.answers.build(FactoryGirl.attributes_for(:answer)) }
end
survey { Survey.create(:name => "Survey Answer") }
@FlaviuSim
FlaviuSim / spec_helper.rb
Created September 25, 2011 18:34
Spec helper with spork
require 'rubygems'
require 'spork'
Spork.prefork do
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
@FlaviuSim
FlaviuSim / Gemfile
Created September 25, 2011 18:36
testing part of the gem file
group :test, :development do
gem 'sqlite3'
gem 'rspec-rails', '~> 2.6.1'
#capybara > webrat: http://zadasnotes.blogspot.com/2011/08/migrating-from-webrat-to-capybara.html?utm_source=rubyweekly&utm_medium=email
gem "capybara", "~> 1.0.0"
#headless js testing that hopefully is faster than selenium
gem "capybara-webkit", "~> 0.6.1"
#supposedly you need this for Mac OS X file system scanning, though it's worked fine so far
gem "rb-fsevent", "~> 0.4.3.1"
# gem 'guard-rspec'
@FlaviuSim
FlaviuSim / Guardfile
Created September 25, 2011 18:37
my guard file
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'rspec', :version => 2, :cli => "--drb" do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec/" }
# Rails example
watch(%r{^spec/.+_spec\.rb$})