jq is useful to slice, filter, map and transform structured json data.
brew install jq
| #! /usr/bin/env python | |
| import re, fileinput, tempfile | |
| from optparse import OptionParser | |
| IGNOREDPREFIXES = [ | |
| 'PRAGMA', | |
| 'BEGIN TRANSACTION;', | |
| 'COMMIT;', | |
| 'DELETE FROM sqlite_sequence;', |
| ++ | |
| (´◓Д◔`) 哇幹!! | |
| ( っค้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้c ) | |
| ++ | |
| (´◓Д◔`) 哇幹!! | |
| ( っค้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้c ) | |
| ++ |
| #!/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 |
| #!/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 |
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)
SSH into your EC2 instance. Run the following:
$ sudo yum install gcc This may return an "already installed" message. That's OK.
$ wget http://download.redis.io/redis-stable.tar.gz && tar xvzf redis-stable.tar.gz && cd redis-stable && make
| 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] |
| #!/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` |