Skip to content

Instantly share code, notes, and snippets.

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

Saiqul Haq saiqulhaq

🏠
Working from home
View GitHub Profile
@saiqulhaq
saiqulhaq / Rails 3 or 4 locale issue (inconsistent value).md
Created June 15, 2019 06:10
Rails 3/4 locale issue (inconsistent value)

Your App might have this issue if you use multithreading server. It's not a bug Rails, but on your app if you don't put before_filter to all controllers. Open this Pull Request for the details rails/rails#34356, rails/rails#34043, and ruby-i18n/i18n#381.

To prevent this issue, change how the way you set I18n.locale = locale code to be in around_filter block, not before_filter.

around_filter :switch_locale

def switch_locale(&action)
  locale = params[:locale] || I18n.default_locale
 I18n.with_locale(locale, &action)
@saiqulhaq
saiqulhaq / Debug Rails autoload issue.md
Created June 15, 2019 06:00
Debug Rails autoload issue

If you read this post, I bet you are getting issue with autoload feature on rails that raises an error on your code and you don't know when or who is triggering the autoload. So, to fix this, just put

puts caller

on your ruby file to check why your ruby file is being autoloaded.

Make it real

Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discuss around concrete examples, not hand-waving abstractions. Don't say you did something, provide a URL that proves it.

Ship it

Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.

Do it with style

@saiqulhaq
saiqulhaq / glorw.txt
Created October 30, 2016 11:12 — forked from stuartpb/glorw.txt
General list of reserved words
### General List of Reserved Words
### Stuart P. Bentley <stuart@testtrack4.com>, June 4, 2013
## This is a general list of words you may want to consider reserving,
## in a system where users can pick any name, in a context where the
## system may use names as well. One prominent example of a system
## where this is the case would be a site that serves pages for users,
## at their username, from the site root, like
## http://twitter.com/stuartpb . In this system, you would want to
## reserve some routes for pages that would commonly be expected to
@saiqulhaq
saiqulhaq / .vimrc
Created October 23, 2016 07:09
vimrc
set nocompatible " be iMproved
filetype off " required!
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle
" required!
Plugin 'VundleVim/Vundle.vim'
@saiqulhaq
saiqulhaq / message-bus.js
Last active April 20, 2016 04:09
Message Bus
/*jshint bitwise: false*/
// please take a look at line numbers 80-85, and 172-177
(function(global, document, undefined) {
'use strict';
longPoller = function(poll,data){
var gotData = false;
var aborted = false;
lastAjax = new Date();
require 'active_record'
require 'bcrypt'
class User < ActiveRecord::Base
PASSWORD_SALT = '$2a$20$ESQ40HbYj00QFse2rbArOe'.freeze
PASSWORD_COST = 15.freeze
establish_connection adapter: 'sqlite3', database: ':memory:'
connection.create_table table_name, force: true do |t|
t.string :email
@saiqulhaq
saiqulhaq / rspec_model_testing_template.rb
Last active August 29, 2015 14:20 — forked from SabretWoW/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@saiqulhaq
saiqulhaq / gist:b8573273e1c1d584cabd
Created December 20, 2014 16:22
rails icon_link_to helper
// Usage
// font awesome
// icon_link_to("Dashboard", internal_path, fa: :dashboard, class: "btn btn-primary")
// bootstrap
// icon_link_to("Dashboard", internal_path, bs: :home, class: "btn btn-primary")
def icon_link_to text, path, options = {}
list = block_given? ? yield : ""
btn_dropdown = options.delete(:dropdown) ? content_tag(:i, "", class: 'fa fa-angle-left pull-right') : ""
if icon = options.delete(:fa) // font-awesome
return link_to(content_tag(:i, "", class: 'fa fa-' + icon.to_s) + content_tag(:span, text) + btn_dropdown, path, options) + list
<script src="your_path/holder.js"></script>