Skip to content

Instantly share code, notes, and snippets.

View atitan's full-sized avatar
🍡

Sh Lin atitan

🍡
View GitHub Profile
@atitan
atitan / sqlite3-to-mysql.py
Created August 15, 2017 18:33
sqlite3 to mysql migration script by Peter sørensen from Redmine forum
#! /usr/bin/env python
import re, fileinput, tempfile
from optparse import OptionParser
IGNOREDPREFIXES = [
'PRAGMA',
'BEGIN TRANSACTION;',
'COMMIT;',
'DELETE FROM sqlite_sequence;',
@atitan
atitan / 160830.poi
Created February 26, 2018 09:47 — forked from wotupset/160830.poi
komica大爆射的gif貼圖跟顏文字
++
(´◓Д◔`) 哇幹!!
( っค้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้c )
++
(´◓Д◔`) 哇幹!!
( っค้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้c )
++
@atitan
atitan / dump.sh
Created November 30, 2018 19:03 — forked from andsens/dump.sh
Backup all MySQL databases into separate files
#!/bin/sh
## backup each mysql db into a different file, rather than one big file
## as with --all-databases. This will make restores easier.
## To backup a single database simply add the db name as a parameter (or multiple dbs)
## Putting the script in /var/backups/mysql seems sensible... on a debian machine that is
## Create the user and directories
# mkdir -p /var/backups/mysql/databases
# useradd --home-dir /var/backups/mysql --gid backup --no-create-home mysql-backup
## Remember to make the script executable, and unreadable by others
@atitan
atitan / enable_bbr.sh
Created December 2, 2018 17:23 — forked from seancheung/enable_bbr.sh
enable google bbr
#!/bin/bash
# get the latest linux kernel at http://kernel.ubuntu.com/~kernel-ppa/mainline/
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.14-rc6/linux-image-4.14.0-041400rc6-generic_4.14.0-041400rc6.201710230731_amd64.deb
# install the kernel
dpkg -i linux-image-4.*.deb
# update grub
# for linode, change kernel in boot settings to GRUB 2
@atitan
atitan / jq-cheetsheet.md
Created December 5, 2018 07:31 — forked from olih/jq-cheetsheet.md
jq Cheet Sheet

Processing JSON using jq

jq is useful to slice, filter, map and transform structured json data.

Installing jq

On Mac OS

brew install jq

@atitan
atitan / jq to filter by value.md
Created December 5, 2018 07:32 — forked from ipbastola/jq to filter by value.md
JQ to filter JSON by value

JQ to filter JSON by value

Syntax: cat <filename> | jq -c '.[] | select( .<key> | contains("<value>"))'

Example: To get json record having _id equal 611

cat my.json | jq -c '.[] | select( ._id | contains(611))'

Remember: if JSON value has no double quotes (eg. for numeric) to do not supply in filter i.e. in contains(611)

@atitan
atitan / aws-ec2-redis-cli.md
Created March 6, 2019 08:20 — forked from todgru/aws-ec2-redis-cli.md
AWS redis-cli on EC2
@atitan
atitan / with_active_support.rb
Created March 8, 2019 07:07 — forked from mbyczkowski/with_active_support.rb
session cookie decrypter for Rails 4.2+
require 'cgi'
require 'json'
require 'active_support'
def verify_and_decrypt_session_cookie(cookie, secret_key_base)
cookie = CGI::unescape(cookie)
salt = 'encrypted cookie'
signed_salt = 'signed encrypted cookie'
key_generator = ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000)
secret = key_generator.generate_key(salt)[0, ActiveSupport::MessageEncryptor.key_len]
@atitan
atitan / spot_termination.sh
Last active August 23, 2019 06:26
starts as EC2 daemon to detect spot instance notice and drain on termination event
#!/bin/bash
yum install -y jq curl
while sleep 5; do
if [ -z $(curl -Isf http://169.254.169.254/latest/meta-data/spot/instance-action) ]; then
/bin/false
else
EC2_INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
EC2_AVAIL_ZONE=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone`
@atitan
atitan / mysql2-mojave.md
Created September 2, 2019 04:08 — forked from fernandoaleman/mysql2-mojave.md
Install mysql2 on MacOS Mojave

Problem

Installing mysql2 gem errors on MacOS Mojave.

Solution

Make sure openssl is installed on Mac via Homebrew.

brew install openssl