Skip to content

Instantly share code, notes, and snippets.

View yetanothernguyen's full-sized avatar

Nguyen Vu Nguyen yetanothernguyen

View GitHub Profile

Setup Database Backup

Instructions to setup MySQL backup on a server and upload to Amazon S3 including email notification on backup failures. Refer to backup gem for more details

Install rbenv and ruby (skip this if your database server already has Ruby installed)

Install rbenv:

$ sudo apt-get update
$ sudo apt-get -y install curl git-core
@yetanothernguyen
yetanothernguyen / gist:604a5a4dbec375ee5685
Created April 6, 2015 11:53
Decrypt Rails 4 session cookie
cookie = CGI.unescape("cookie here")
secret_key_base = "secret key here"
encrypted_cookie_salt = "encrypted cookie"
encrypted_signed_cookie_salt = "signed encrypted cookie"
key_generator = ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000)
secret = key_generator.generate_key(encrypted_cookie_salt)
sign_secret = key_generator.generate_key(encrypted_signed_cookie_salt)
@yetanothernguyen
yetanothernguyen / backup.rb
Last active August 29, 2015 14:10
Backup gem config file
# encoding: utf-8
##
# Backup Generated: 8share_backup
# Once configured, you can run the backup with the following command:
#
# $ backup perform -t backup [-c <path_to_configuration_file>]
#
# For more information about Backup's components, see the documentation at:
# http://meskyanichi.github.io/backup
<iframe id="donation-iframe" data-src="http://unicef.my/donations/confirmed?iframe=true" width="700px" height="700px" seamless="true" border="0" style="margin: 0; padding: 0; border: none"></iframe>
<script type="text/javascript">
window.onload = function() {
var params = window.location.toString().split('?')[1],
iframe = document.getElementById('donation-iframe');
iframe.src = iframe.getAttribute('data-src') + '&' + params;
};
</script>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Todo</title>
<link rel="stylesheet" type="text/css" href="todo.css">
<script type="text/javascript">
window.addEventListener('load', run);
function run() {
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
# Ruby dependencies
sudo apt-get -y install build-essential openssl libreadline6 libreadline6-dev curl zlib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison git-core libcurl4-openssl-dev
# Imagemagick
sudo apt-get -y install imagemagick
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
#!/bin/sh
# Map LISTENing TCP ports to their PIDs using lsof
LSOF=/usr/sbin/lsof
# e.g. netstat -an
# 127.0.0.1.25 *.* 0 0 49152 0 LISTEN
# *.22 *.* 0 0 49152 0 LISTEN
class TwerkBot < RTanque::Bot::Brain
NAME = 'twerk_bot'
include RTanque::Bot::BrainHelper
def tick!
## main logic goes here
@tick_count ||= 0
@tick_count+=1
command.speed = MAX_BOT_SPEED if command.speed == nil
@yetanothernguyen
yetanothernguyen / gist:3808011
Last active October 11, 2015 05:08
Setup Development Machine