Skip to content

Instantly share code, notes, and snippets.

View crifat's full-sized avatar

Rifatul Islam Chayon crifat

  • Dhaka, Bangladesh
View GitHub Profile
@crifat
crifat / rails-5-6-ubuntu-mina-puma-nginx.md
Created August 21, 2020 22:16 — forked from wafiq/rails-5-6-ubuntu-mina-puma-nginx.md
How to deploy Rails 5/6 in Ubuntu VM using Mina deployment with Puma webserver and Nginx

Rails 5 and 6 Deployment with Ubuntu, Mina, Puma and Nginx

Based on this tutorial but simplified and inlined. Particularly removed any Rails and 3rd party services part, assumed you just need deployment to any Ubuntu machine.

Prerequisite

  1. A functional Rails app
  2. Hosted Git repository (Github, Bitbucket, Gitlab)
  3. Cloud hosting account (Digital Ocean, Vultr, Linode, Lightsail)
  4. Local SSH account
@crifat
crifat / my_sql_encryption.rb
Created July 1, 2020 13:42 — forked from JohnZavyn/my_sql_encryption.rb
MySQL AES Encryption for Ruby
require 'openssl'
# This module provides AES encryption compatible with MySQL AES_ENCRYPT
# and AES_DECRYPT functions.
module MySQLEncryption
# Takes an unencrypted text string, encrypts it with the password,
# and encodes the results to a hexadecimal string
def self.mysql_encrypt(unencrypted_text, password)
encrypt(unencrypted_text, mysql_key(password))
const formatDate = (date) => date.getFullYear() + '-' + (date.getMonth() + 1).toString().padStart(2, '0') + '-' + date.getDate().toString().padStart(2, '0');
// OR
Date.prototype.formatDate = function() {
return (this.getFullYear() + '-' + (this.getMonth() + 1).toString().padStart(2, '0') + '-' + this.getDate().toString().padStart(2, '0'));
};
@crifat
crifat / rails_api_token_auth_with_tiddle.md
Created August 13, 2017 21:13 — forked from brunofacca/rails_api_token_auth_with_tiddle.md
Rails API token authentication with Tiddle gem in apps with web views

This gist attempts to explain how to implement token authentication in Rails, using Devise and Tiddle. Tiddle was designed to provide token auth for API-only Rails apps. However, the following instructions will enable you to use it in Rails apps which have both APIs and web views.

##Why Tiddle?

Devise is the obvious choice for authentication on Rails. However, token authentication was

@crifat
crifat / new_gist_file_0
Created June 7, 2017 04:32
Sierra SSH permission fix
As of macOS Sierra 10.12.2 Apple added an ssh_config option called UseKeychain which allows a 'proper' resolution to the problem. Add the following to your ~/.ssh/config file:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
From the ssh_config man page on 10.12.2:
UseKeychain
@crifat
crifat / string_to_param.rb
Last active July 28, 2017 05:19
Convert String into parameter
<%= link_to "Leads", leads_path(q: eval(@email_campaign.lead_query)) %>
### Caution!
@crifat
crifat / mac_commands
Last active March 5, 2017 18:01
Various Mac Commands
# Start Redis server temporarily:
redis-server /usr/local/etc/redis.conf
# Make an app runable
sudo xattr -cr /Application/Appname.app
@crifat
crifat / create_google_calendar_event.rb
Last active January 6, 2018 17:17
Create/Update a Google Calendar Event. Create a .ics File with iCaneldar gem
if guide && (guide.user.access_token.present? && guide.user.refresh_token.present? && guide.user.gmail.present?)
guide.refresh_access_token
client = Google::APIClient.new
client.authorization.access_token = guide.user.access_token
service = client.discovered_api('calendar', 'v3')
result = client.execute(:api_method => service.events.get,
:parameters => {'calendarId' => 'primary', 'eventId' => "#{self.created_on.to_i}"})
@crifat
crifat / stripe_refund.rb
Last active September 17, 2017 15:48
Refund a Stripe Charge
Stripe.api_key = ENV['STRIPE_CONNECT_SECRET_KEY']
begin
ch = Stripe::Charge.retrieve(self.charge_id)
r = ch.refunds.create(:amount => (self.amount * 100).to_i, :reverse_transfer => true, :refund_application_fee => true)
rescue => e
errors[:base] << e.message
return false
end
@crifat
crifat / stripe_create_charge.rb
Created March 5, 2017 11:56
Stripe Create Charge
Stripe.api_key = ENV['STRIPE_CONNECT_SECRET_KEY']
c = Stripe::Charge.create({
:amount => amount,
:currency => "usd",
:statement_descriptor => self.network.name[0..21],
:source => token,
:metadata => {payment_id: self.id},
:description => "#{self.try(:description_for_email)}, #{self.client.try(:full_name)}, #{Date.today.to_s(:long)}",
:destination => self.network.uid,
:application_fee => ((self.amount * 100) * 0.029).to_f.round(0) + 30