Skip to content

Instantly share code, notes, and snippets.

View meinac's full-sized avatar

Mehmet Emin İNAÇ meinac

  • Modomoto
  • Berlin
View GitHub Profile
@meinac
meinac / gist:7222298
Created October 29, 2013 20:45
using scopes on ransack search and sort
#paste this code in your ransack.rb initializer
#if you want to use scopes on search or sort please use Class.ransack_with_scopes instead of Class.search
Ransack::Adapters::ActiveRecord::Base.class_eval do
def ransack(params = {}, options = {}, scope_used_on_sort = false)
Ransack::Search.new(self, params, options, scope_used_on_sort)
end
def ransack_with_scopes(params = {}, options = {})
scope_used_on_sort = false
ransack_scope = self
ransack_params = {}
@meinac
meinac / gist:0f4806f6c812b65db4d8
Created June 22, 2015 16:27
Array.uniq.to_set vs Array.to_set
require 'benchmark/ips'
require 'set'
#init array
arr = Array.new
1000.times do
arr << (rand * 20).to_i
end
Benchmark.ips do |x|
defmodule Meinac.User do
use Meinac.Web, :model
schema "users" do
field :first_name, :string
field :last_name, :string
field :email, :string
field :password_digest, :string
field :password, :string, virtual: true
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(false) do
source 'https://rubygems.org'
gem 'activerecord', '4.2.6'
@meinac
meinac / cron.config
Created March 22, 2016 12:57
AWS create cronjob for rake tasks
container_commands:
01_remove_old_cron_jobs:
command: "crontab -u ec2-user -r || exit 0"
test: '[ -n "$tier" ] && [ "$tier" = "worker" ]'
02_create_cron_command:
command: "echo '0 * * * * source /home/ec2-user/.bashrc && pushd /var/app/current && rake task_name' > /home/ec2-user/cron_command"
test: '[ -n "$tier" ] && [ "$tier" = "worker" ]'
10_run_cron_job:
command: "crontab -u ec2-user /home/ec2-user/cron_command"
test: '[ -n "$tier" ] && [ "$tier" = "worker" ]'