Skip to content

Instantly share code, notes, and snippets.

View nglx's full-sized avatar
✌️
no mud no lotus

marcin naglik nglx

✌️
no mud no lotus
View GitHub Profile
@nglx
nglx / 0_reuse_code.js
Last active August 29, 2015 14:10
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@nglx
nglx / rubycheck_1.rb
Last active August 29, 2015 14:11 — forked from anonymous/rubycheck_1
foo = :bar if false
foo.nil? # => raises an error because...?
@nglx
nglx / rom_yesql_with_sequel_rails.rb
Last active August 29, 2015 14:18
Reusing sequel-rails connection in rom-yesql
ROM::Yesql::Repository.class_eval do
def initialize(uri, options = {})
super
@connection = Sequel::Model.db
initialize_queries
ROM::Yesql::Relation.query_proc(query_proc)
ROM::Yesql::Relation.load_queries(queries)
end
end
@nglx
nglx / gist:1364123
Created November 14, 2011 15:06
test
-- fdsafdas
- fasdfdsa
fdasfdas
@nglx
nglx / gist:3787676
Created September 26, 2012 12:15 — forked from bjallen/gist:3723463
city impact on results
# see what the confidence code means here:
# http://www.mapquestapi.com/geocoding/geocodequality.html
Web::Address.from_params({ :street => "Canal Road", :city => "Orleans", :state => "MA", :country => "US" })
[{"country_name"=>"United States",
"city"=>"Orleans",
"@name"=>"location",
"latitude"=>41.796795,
"country"=>"US",
ActiveRecord.where('created_at > ?', Time.now).to_sql
module Scope
def self.included(base)
base.has_scope :with_name_like
base.has_scope :with_title_like
end
end
class PostsController < ApplicationController
include Scope
@nglx
nglx / has_scope.rb
Last active December 24, 2015 20:38
class UsersController < ApplicationController
include User::SearchScope
def index
search_params = params[:user_search] || {}
@users = apply_scopes(User, search_params)
end
end
class User < ActiveRecord::Base
class UsersController < ApplicationController
def index
user_search = UserSearch.new(params[:user_search])
@users = User.by_user_search(user_search)
end
end
# user search form object
class UserSearch
include Virtus.model
#!/usr/bin/env ruby
require 'benchmark'
REGEXPS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,
]