Skip to content

Instantly share code, notes, and snippets.

View Amitesh's full-sized avatar

Amitesh Kumar Amitesh

View GitHub Profile
@Amitesh
Amitesh / gist:1113683
Created July 29, 2011 12:00
Open popup window in center of screen in javascript
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 / allure-env-config.ts
Created June 15, 2023 15:59
allure-env-config
export const config = {
// ...
reporters: [['allure', {
outputDir: 'allure-results',
disableWebdriverStepsReporting: true,
disableWebdriverScreenshotsReporting: true,
reportedEnvironmentVars: {
'foo': 'Hello world!',
foobar: 'Goodbye world',
'Foo / Bar': process.env.foobar,

Decorator in JavaScript and Typescript

  • In JavaScript, we can apply decorators to class fields, methods, and the entire class. Therefore, we can’t use decorators on plain objects. They only work with classes.
  • Decorators are not a standard JavaScript feature. They are in stage 3 of the ECMA TC39 specification phase. To use JavaScript Decorators we need to set up a transpiler tool in our development environment, like Babel.
  • Decorator is concept and can be in form of function or start with @.

There are function decorator and class and it's member decorator. Fot indepenedent/global function we can decorate it by wrapping it inside another function but for class decorator we can use the @ symbol and typescript or bable library.

References

@Amitesh
Amitesh / gist:1389891
Created November 23, 2011 20:57
Problem with Kaminari pagination on Rails Active Record joins
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 / backup-to-git.sh
Created December 9, 2011 12:53 — forked from aarongustafson/backup-to-git.sh
DB Backup to Git
#!/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 June 25, 2011 07:51
Set Rails Engine/Gem public assets path, to server it from Engine/Gem itself
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 / unzip-folder.rb
Created September 28, 2011 07:26
unzip folder in ruby
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 April 28, 2012 12:41
Accessing Helper modules in rails
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 / Logs.log
Last active May 15, 2018 17:05
Steps to create a angular 6 project with lib
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)
@Amitesh
Amitesh / pickadate-demo.html
Created April 10, 2018 21:28
pickadate-demo
<!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">