Skip to content

Instantly share code, notes, and snippets.

View blackxored's full-sized avatar
🏠
Working from home

Adrian Perez blackxored

🏠
Working from home
View GitHub Profile
@blackxored
blackxored / gist:705364
Created November 18, 2010 18:11
Import CSV users into redmine
# csv_import_users.rake
# Bulk user provisioning for Redmine using CSV file
# Copyright (C) 2010 - Adrian Perez <adrianperez.deb@gmail.com>
# Licensed under GPL 3.
require 'csv'
namespace :redmine do
task :csv_import_users => :environment do
@first_row = true
class String
def method_missing(name, *args, &block)
name == :ghost_capitalize ? capitalize : super
end
end
require 'benchmark'
Benchmark.bmbm do |b|
b.report "Normal method" do
1_000_000.times { "abc".capitalize }
@blackxored
blackxored / client.coffee
Created July 2, 2012 04:44
Token authentication with Devise and Backbone
jQuery.ajaxSetup(
beforeSend: (xhr) ->
xhr.setRequestHeader('X-Auth-Token',
App.Session.getAuthenticationToken())
)
# ...
class App.Session
# ...
getAuthenticationToken: ->
10 | _ -> 10 (+5)
| _________/ \ -----------------------
5 | | -> 5 ____ 5 (-5) | Criteria color legend |
| / | e.g: |
0 |__________________________________ | [] (blue): Google PR |
2012-09-24 2012-10-17 2012-10-24 -----------------------
@blackxored
blackxored / api_helper.rb
Created November 20, 2012 01:05
RSpec::Rails, Capybara, Rack::Test errors on last_response
# ./spec/support/api/helper.rb
module ApiHelper
include Rack::Test::Methods
def app
Rails.application
end
end
RSpec.configure do |c|
#!/usr/bin/env ruby
#^syntax detection
site 'http://community.opscode.com/api/v1'
cookbook 'build-essential'
cookbook 'ruby_build', :git => 'git://github.com/fnichol/chef-ruby_build.git'
cookbook 'rbenv', :git => 'git://github.com/fnichol/chef-rbenv'
cookbook 'apt', :git => 'git://github.com/opscode-cookbooks/apt'
group :development, :test do
# ...
if RUBY_PLATFORM.downcase.include?("darwin")
gem 'rb-fsevent'
gem 'growl'
end
if RUBY_PLATFORM.downcase.include?("linux")
gem 'libnotify'
=begin
Machine Learning study predicts the Backbone JavaScript framework as the most
successful emerging web technology, with reproduceable results.
Here's one of such reproductions.
=end
[29] pry(main)> !!defined?(Rails) #=> true
[30] pry(main)> User.count #=> 385 users
[31] pry(main)> User.where(:"profile.skills".in => ["forgery"]).size #=> 378 made-up users
[32] pry(main)> User.where(:"profile.skills".in => ["Ruby"]).size #=> 1 errrr, just me?
module ApiAuthOverride
[:get, :post, :put, :delete, :patch].each do |method|
define_method(method) do |url, params=nil|
access_token = { access_token: current_token }
super(url, params ? params.merge(access_token) : access_token)
end
end
end
# ...
$(document).on 'click', '.highlight-trigger' , (evt) ->
evt.preventDefault()
console.log "On highlight trigger"
highlightCurrentSelection() and deselectEverything()