Skip to content

Instantly share code, notes, and snippets.

View elvanja's full-sized avatar

Vanja Radovanović elvanja

View GitHub Profile
@elvanja
elvanja / 1_rcat_tests.rb
Created October 20, 2011 18:49 — forked from practicingruby/1_rcat_tests.rb
Implementing a clone of UNIX cat in Ruby
# Task: Implement the rcat utility and get these tests to pass on a system
# which has the UNIX cat command present
# To see Gregory Brown's solution, see http://github.com/elm-city-craftworks/rcat
# Feel free to publicly share your own solutions
# If you want to see detailed commentary on how to solve this problem
# please subscribe to the Practicing Ruby Journal ( practicingruby.com )
# An article on this topic will be released on Tuesday 10/18.
@elvanja
elvanja / spec_helper_without_rails.rb
Created November 19, 2012 07:11
Spec helper without Rails
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
# Requires all extra / autoload paths, @see /config/initializers/auto_require.rb
# Recommendation: do not rely on autoload for domain objects, use this just for specs
unless defined?(Rails)
%W(
app/persistence
app/representers
@elvanja
elvanja / rspec_without_rails.sh
Created November 19, 2012 07:13
Run RSpec without Rails
#!/bin/sh
grep spec_helper_without_rails -Rl spec/* | xargs rspec
@elvanja
elvanja / grack_auth.rb
Created December 3, 2012 13:30
Gitlab grack authentication with ldap and possibly other providers
require "net/ldap"
# assumes ldap login is present in User.username
# flow in general:
# * find user either by email or username (using provided login)
# * if ldap enabled and user provider is ldap, authenticate over ldap
# * else validate plain password
module Grack
class Auth < Rack::Auth::Basic
attr_accessor :user, :project
@elvanja
elvanja / grack_auth.rb
Created December 3, 2012 13:36
Gitlab grack authentication with ldap when username is not in schema
require "net/ldap"
=begin
fix for older versions, without username in User model
flow in general:
* authenticate user with ldap
return user's email if authenticated, otherwise nil
* if email retrieved
(ldap authenticated the user)
- find user in Gitlab database by that email
@elvanja
elvanja / bulk_add_permission_ldap_groups_without_username.rake
Last active October 13, 2015 15:08
Gitlab bulk add permissions respecting ldap groups (without username, for Gitlab version <= 3.1.0)
require "net/ldap"
# if a project belongs to a ldap group
# add users from ldap group to the project
# remove all other users from the project
# else
# add all users as usual
desc "Add or removes users from projects (admin users are added as masters) respecting LDAP and project groups"
task :add_or_remove_users_from_project_teams_using_ldap_groups => :environment do |t, args|
gl = Gitlab.config
@elvanja
elvanja / .rspec
Created December 28, 2012 07:42 — forked from coreyhaines/.rspec
--colour
-I app
@elvanja
elvanja / deploy_to_heroku.sh
Created January 5, 2013 22:45
Deploy to heroku from current branch Precompiles assets but doesn't pollute the workspace
#!/bin/sh
# http://stackoverflow.com/questions/3878624/how-do-i-programmatically-determine-if-there-are-uncommited-changes
require_clean_work_tree () {
# Update the index
git update-index -q --ignore-submodules --refresh
err=0
# Disallow unstaged changes in the working tree
if ! git diff-files --quiet --ignore-submodules --; then
@elvanja
elvanja / amazon_api_spec.rb
Created January 6, 2013 21:40
An example of using VCR to speed up integration testing Amazon API over Vacuum gem
require 'spec_helper_without_rails'
require 'vacuum'
describe "search by keywords golden path" do
let(:credentials) { YAML::load(File.open("config/amazon.yml"))["test"] }
let(:provider) { Vacuum.new.tap { |provider| provider.configure(credentials) } }
let(:search_matcher) {
lambda do |new_request, saved_request|
new_keywords = new_request.uri[/Keywords=(.*)Operation=.*/, 1]
@elvanja
elvanja / hash_play_time.groovy
Created January 8, 2013 11:28
A little comparison between groovy and ruby nested hashes with defaults
class Person {
public name
public gender
public age
public Person(name, gender, age) {
this.name = name
this.gender = gender
this.age = age
}