Skip to content

Instantly share code, notes, and snippets.

View khanhnguyen's full-sized avatar

Khanh Nguyen khanhnguyen

View GitHub Profile
@khanhnguyen
khanhnguyen / encrypt_decrypt.rb
Created May 2, 2018 03:45 — forked from wteuber/encrypt_decrypt.rb
Simply encrypt and decrypt Strings in ruby.
require 'openssl'
class String
def encrypt(key)
cipher = OpenSSL::Cipher::Cipher.new('DES-EDE3-CBC').encrypt
cipher.key = Digest::SHA1.hexdigest key
s = cipher.update(self) + cipher.final
s.unpack('H*')[0].upcase
end
perl msgconvert.pl YourMessage.msg
useradd -G www-data iain
chown -R www-data:www-data /var/www/example.com
chmod 775 /var/www
sudo /opt/nginx/sbin/nginx
@khanhnguyen
khanhnguyen / caches_action.rb
Last active August 29, 2015 14:26 — forked from marshluca/caches_action.rb
Rails Action Cache
class ListsController < ApplicationController
before_filter :authenticate, :except => :public
caches_page :public
caches_action :index, :if => proc do
!request.format.json? # cache if is not a JSON request
end
caches_action :show, :cache_path => { :project => 1 },
@khanhnguyen
khanhnguyen / gist:60bfa64376066774662f
Created July 21, 2015 08:04
run whenever in development mode
whenever --update-crontab --set environment=development
crontab -l
@khanhnguyen
khanhnguyen / gist:fb911555fe378488e319
Created July 8, 2015 07:59
create index and import
Job.__elasticsearch__.create_index!
Job.__elasticsearch__.import force: true
tail -f log/development.log | grep -vE 'asset|system|shared|layout|blog|jobs'
function get_avatar_from_service(service, userid, size) {
// this return the url that redirects to the according user image/avatar/profile picture
// implemented services: google profiles, facebook, gravatar, twitter, tumblr, default fallback
// for google use get_avatar_from_service('google', profile-name or user-id , size-in-px )
// for facebook use get_avatar_from_service('facebook', vanity url or user-id , size-in-px or size-as-word )
// for gravatar use get_avatar_from_service('gravatar', md5 hash email@adress, size-in-px )
// for twitter use get_avatar_from_service('twitter', username, size-in-px or size-as-word )
// for tumblr use get_avatar_from_service('tumblr', blog-url, size-in-px )
// everything else will go to the fallback
// google and gravatar scale the avatar to any site, others will guided to the next best version
class NotificationMailer < ActionMailer::Base
def new_notification_email(notification,receiver)
@notification = notification
@receiver = receiver
subject = notification.subject.to_s
subject = strip_tags(subject) unless subject.html_safe?
mail :from => "#change your own", :to => receiver.send(Mailboxer.email_method,notification),
:subject => t('mailboxer.notification_mailer.subject', :subject => subject),
:template_name => 'new_notification_email'