Skip to content

Instantly share code, notes, and snippets.

View sur's full-sized avatar

Sur Max sur

View GitHub Profile
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 04:07
Render Facebook Like button after Ajax Call.
# add the following JS code at the end of the ajax call.
FB.XFBML.parse();
@sur
sur / gist:4250400
Created December 10, 2012 12:58
Pagination for Parse Resource
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 October 12, 2015 13:57
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 September 20, 2012 11:53 — forked from wrs/app_config.rb
Simple Rails app configuration class
# 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 September 2, 2012 15:57
will paginate initializer file
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 August 29, 2012 14:48
Iconv vs String.encode
# 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 August 23, 2012 05:33
validate formats
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
new PeriodicalExecuter(function(){new Ajax.Request('/main/some_method', {asynchronous:true, evalScripts:true})}, 2)
@sur
sur / rake task to create database dumps
Created September 25, 2008 09:40
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