Skip to content

Instantly share code, notes, and snippets.

Avatar

Amitesh Kumar Amitesh

View GitHub Profile
View backup-to-git.sh
#!/bin/bash
##
# MySQL DB dump to Git commit
#
# Dumps the specified mysql database to the given location and commits it and
# the previous database to the Git repository.
#
# It is assumed you have already setup the Git respository to only be the
# a checkout of the database backup location
@Amitesh
Amitesh / gist:1046269
Created Jun 25, 2011
Set Rails Engine/Gem public assets path, to server it from Engine/Gem itself
View gist:1046269
require "rails"
module MyEngine
class Engine < Rails::Engine
# We can add all of the public assets from our engine and make them
# available to use. This allows us to use javascripts, images, stylesheets
# etc.
initializer "static assets" do |app|
app.middleware.insert_before(::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public")
@Amitesh
Amitesh / gist:1113683
Created Jul 29, 2011
Open popup window in center of screen in javascript
View gist:1113683
var top = window.screen.height - 300;
top = top > 0 ? top/2 : 0;
var left = window.screen.width - 400;
left = left > 0 ? left/2 : 0;
var uploadWin = window.open(url,"Upload Chapter content","width=400,height=300" + ",top=" + top + ",left=" + left);
uploadWin.moveTo(left, top);
uploadWin.focus();
@Amitesh
Amitesh / unzip-folder.rb
Created Sep 28, 2011
unzip folder in ruby
View unzip-folder.rb
require 'rubygems'
require 'zip/zip'
def unzip_file (file, destination)
Zip::ZipFile.open(file) { |zip_file|
zip_file.each { |f|
f_path=File.join(destination, f.name)
FileUtils.mkdir_p(File.dirname(f_path))
zip_file.extract(f, f_path) unless File.exist?(f_path)
}
@Amitesh
Amitesh / rails_helper.rb
Created Apr 28, 2012
Accessing Helper modules in rails
View rails_helper.rb
Accessing Helper modules in rails
http://www.funonrails.com/2010/12/accessing-helper-modules-in-rails.html
1. Helper methods all the time for views
class ApplicationController < ActionController::Base
helper :all# include all helpers, all the time for views
end
@Amitesh
Amitesh / gist:1389891
Created Nov 23, 2011
Problem with Kaminari pagination on Rails Active Record joins
View gist:1389891
Error Type : 1. Use "includes" instead of "joins" with kaminari pagination.
example :
books = Book.joins( :other_category ).where(['books.published_on is not null and other_categories.name like ?', "%#{category_name}%"]).order('books.title').page( page ).per( per )
it makes sql for counting the record as :
SELECT COUNT(*) FROM `books` WHERE ( books.id IN (SELECT DISTINCT other_categories.book_id FROM other_categories WHERE other_categories.name LIKE '%Fiction%')) LIMIT 10 OFFSET 20
This sql failed to return the count dues to limit and offset.
@Amitesh
Amitesh / Logs.log
Last active May 15, 2018
Steps to create a angular 6 project with lib
View Logs.log
Amiteshs-MacBook-Pro:fiserv amitesh$ ng new simpleNgxDatagrid --directory simple-ngx-datagrid
CREATE simple-ngx-datagrid/README.md (1034 bytes)
CREATE simple-ngx-datagrid/angular.json (3492 bytes)
CREATE simple-ngx-datagrid/package.json (1323 bytes)
CREATE simple-ngx-datagrid/tsconfig.json (384 bytes)
CREATE simple-ngx-datagrid/tslint.json (2805 bytes)
CREATE simple-ngx-datagrid/.editorconfig (245 bytes)
CREATE simple-ngx-datagrid/.gitignore (503 bytes)
CREATE simple-ngx-datagrid/src/environments/environment.prod.ts (51 bytes)
CREATE simple-ngx-datagrid/src/environments/environment.ts (631 bytes)
View pickadate-demo.html
<!doctype html>
<meta charset="utf-8">
<meta name="author" content="Amsul - http://amsul.ca">
<meta name="viewport" content="width=device-width,user-scalable=no">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
@Amitesh
Amitesh / gist:1128275
Created Aug 5, 2011
Undefined entity &nbsp; while XML parsing error in firefox
View gist:1128275
XML parsing does not support &nbsp; entity. &nbsp; is XHTML entity. If we parse the html or xml or html as xml then you get "Undefined entity" error in firefox error console. To make it working use unicode of &nbsp; (non-breakibg space character) &#160; or simply put space (" " or &#32;).
for example :
<div> &nbsp; hello I am going to break. If you are going to use xml parser :( </div>
Corrected as :
<div> &#160; hello I am going to break. If you are going to use xml parser :( </div>
@Amitesh
Amitesh / word-wrap
Created Nov 26, 2011
Word wrap in Ruby
View word-wrap
# we can change the <wbr> and <br> as per our requirement.
def wrap_long_string(text, max_width = 20)
if text.blank?
return text
end
sp = text.split(/\n/)
sp.collect!{|s|
s = (s.length < max_width) ? s : s.scan(/.{1,#{max_width}}/).join("<wbr>")
}