Skip to content

Instantly share code, notes, and snippets.

Avatar

Sur Max sur

View GitHub Profile
View Delete Redis Keys
redis-cli
redis 127.0.0.1:6379> KEYS sidetiq
(empty list or set)
redis 127.0.0.1:6379> KEYS sidetiq:*
1) "sidetiq:RecurrentMailDownloaderWorker:next"
2) "sidetiq:RecurrentMailDownloaderWorker:last"
redis 127.0.0.1:6379> DEL sidetiq:RecurrentMailDownloaderWorker:next
(integer) 1
redis 127.0.0.1:6379> DEL sidetiq:RecurrentMailDownloaderWorker:last
(integer) 1
@sur
sur / Render FB Like after Ajax
Created May 17, 2013
Render Facebook Like button after Ajax Call.
View Render FB Like after Ajax
# add the following JS code at the end of the ajax call.
FB.XFBML.parse();
@sur
sur / gist:4250400
Created Dec 10, 2012
Pagination for Parse Resource
View gist:4250400
example action and view code:
def index
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
kids = current_day_care.kids(page)
@kids = kids[:kids]
unless kids[:total].to_i.zero?
@kids_pages = (1..kids[:total]).to_a.paginate(:page => page, :per_page => Kid::PerPage)
end
end
@sur
sur / Array In Groups
Last active Oct 12, 2015
array in groups
View Array In Groups
1.9.3p194 :001 > a = 1,2,3,4,5,6,6
=> [1, 2, 3, 4, 5, 6, 6]
1.9.3p194 :002 > a.methods.grep /groups/
=> [:in_groups_of, :in_groups]
1.9.3p194 :003 > a.in_groups(2)
=> [[1, 2, 3, 4], [5, 6, 6, nil]]
1.9.3p194 :004 > a.in_groups_of(2)
=> [[1, 2], [3, 4], [5, 6], [6, nil]]
@sur
sur / app_config.rb
Created Sep 20, 2012 — forked from wrs/app_config.rb
Simple Rails app configuration class
View app_config.rb
# Simple configuration system
#
# The configuration is represented as a tree of keys. Examples:
#
# AppConfig['key']
# AppConfig['key','subkey']
# AppConfig['key.subkey']
#
# An optional default value can be specified:
#
@sur
sur / application_helper.rb
Created Sep 2, 2012
will paginate initializer file
View application_helper.rb
module ApplicationHelper
def page_links(pages)
will_paginate(pages, :class => 'pagination', :inner_window => 2, :outer_window => 0, :renderer => BootstrapLinkRenderer, :previous_label => '«'.html_safe, :next_label => '»'.html_safe)
end
end
@sur
sur / gist:3513708
Created Aug 29, 2012
Iconv vs String.encode
View gist:3513708
# using Iconv
iv = Iconv.new("UTF-8//IGNORE", "UTF-8")
content = iv.iconv(content)
# using String.encode
"string".encode(Encoding::UTF_8, :invalid => :replace, :undef => :replace, :replace => '')
@sur
sur / formats.rb
Created Aug 23, 2012
validate formats
View formats.rb
require 'open-uri'
class Some < ActiveRecord::Base
# validates urls
validates :url, :presence => true, :format => /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix,
:uniqueness => true
# validates email
View periodic executor
new PeriodicalExecuter(function(){new Ajax.Request('/main/some_method', {asynchronous:true, evalScripts:true})}, 2)
@sur
sur / rake task to create database dumps
Created Sep 25, 2008
rake task to create database dumps
View rake task to create database dumps
require 'yaml'
require 'fileutils'
desc "takes db backup and stores it to /var/backups/timestamp.sql with"
task :db_backup => :environment do
production = YAML.load(File.read(File.join(RAILS_ROOT, "config/database.yml")))['production']
db = production['database']
username = production['username']
password = production['password']
t = Time.now
You can’t perform that action at this time.