Skip to content

Instantly share code, notes, and snippets.

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

Shah Zaib shah743

🏠
Working from home
  • Islamabad, PK
View GitHub Profile
@shah743
shah743 / twitter_widget_id_extractor.rb
Last active May 11, 2016 14:42
Get twitter embed widget's ID dynamically
class TwitterWidgetIdExtractor
WIDGET_SETTING_URL = "https://twitter.com/settings/widgets/new/user?screen_name="
SIGNIN_URL = "https://twitter.com/login"
attr_accessor :screen_name, :twitter_username, :twitter_password
def initialize(screen_name, twitter_username, twitter_password)
@screen_name = screen_name
@twitter_username = twitter_username
@twitter_password = twitter_password
@shah743
shah743 / rails_confirm_override.js.coffee
Last active January 26, 2016 04:37 — forked from stevenspiel/rails_confirm_override.js.coffee
Replace Rails confirm with sweetalert2 popup. (https://github.com/limonte/sweetalert2). It overrides the default javascript (from jquery_ujs), which skips any other popup.
$.rails.allowAction = (link) ->
if link.data('confirm')
$.rails.showConfirmationDialog(link)
false
else
true
# User click confirm button
$.rails.confirmed = (link) ->
link.data('confirm', null)
# config/routes.rb
%w( 404 422 500 ).each do |code|
get code, :to => "errors#show", :code => code
end
# app/views/errors/404.html.haml
%h1 404 - Not Found
class ErrorsController < ApplicationController
@shah743
shah743 / ssl_puma.sh
Created April 13, 2016 05:36
localhost SSL with puma
# 1) Create your private key (any password will do, we remove it below)
$ cd ~/.ssh
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@shah743
shah743 / compression.rb
Created August 31, 2016 09:45 — forked from remino/compression.rb
Ruby on Rails: Minify HTML, CSS, & JS, and compress with gzip https://remino.net/rails-html-css-js-gzip-compression/
# config/initializers/compression.rb
Rails.application.configure do
# Use environment names or environment variables:
# break unless Rails.env.production?
break unless ENV['ENABLE_COMPRESSION'] == '1'
# Strip all comments from JavaScript files, even copyright notices.
# By doing so, you are legally required to acknowledge
# the use of the software somewhere in your Web site or app:
@shah743
shah743 / NoVNC_Paste.js
Created October 19, 2017 05:41 — forked from byjg/NoVNC_Paste.js
How to Paste code to NoVNC.
// This will open up a prompt for text to send to a console session on digital ocean
// Useful for long passwords
(function () {
window.sendString = function (str) {
f(str.split(""));
function f(t) {
var character = t.shift();
var i=[];
var code = character.charCodeAt();
var needs_shift = character.match(/[A-Z!@#$%^&*()_+{}:\"<>?~|]/);
@shah743
shah743 / deploy.rb
Created October 26, 2018 12:43 — forked from yanyingwang/deploy.rb
mina+puma+nginx
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
# require 'mina/rbenv' # for rbenv support. (http://rbenv.org)
require 'mina/rvm' # for rvm support. (http://rvm.io)
require 'mina/puma'
require 'mina/nginx'
# Basic settings:
@shah743
shah743 / rails_confirm_override.js.coffee
Created October 29, 2018 08:10
SweetAlert2 rails confirm
$.rails.allowAction = (link) ->
if link.data('confirm')
$.rails.showConfirmationDialog(link)
false
else
true
# User click confirm button
$.rails.confirmed = (link) ->
link.data('confirm', null)
@shah743
shah743 / export.rb
Created July 18, 2019 06:32
Export From Console to CSV
require 'csv'
file = "#{Rails.root}/public/user_data.csv"
products = Product.order(:first_name)
headers = ["Product ID", "Name", "Price", "Description"]
CSV.open(file, 'w', write_headers: true, headers: headers) do |writer|
products.each do |product|
@shah743
shah743 / admin_mailer.rb
Created September 25, 2019 05:12
Protecting a Rails app from small scripted attacks
#app/mailers/admin_mailer.rb
class AdminMailer < ApplicationMailer
default from: "...", to: "..."
def rack_attack_notification(name, start, finish, request_id, remote_ip, path, request_headers)
@name = name
@start = start
@finish = finish
@request_id = request_id