Skip to content

Instantly share code, notes, and snippets.

View niraj-shah's full-sized avatar
🏠
Working from home

Niraj Shah niraj-shah

🏠
Working from home
View GitHub Profile
@niraj-shah
niraj-shah / s3cmd_sync.sh
Last active June 9, 2021 14:21
s3cmd commands to sync folders to AWS S3
# Command Line to run from terminal
# Logs result to file s3_backup.log
# Command will run in the background
s3cmd sync -v /path/to/folder/ s3://s3-bucket/folder/ > s3_backup.log 2>&1 &
# Crontab command to sync folder to S3
# Command will run 1am every day and logs result to /root/s3_backup.log
0 1 * * * /usr/bin/s3cmd sync -rv /path/to/folder/ s3://s3-bucket/folder/ >> /root/s3_backup.log
@niraj-shah
niraj-shah / install_imagemagick.sh
Created April 6, 2013 19:44
Install ImageMagick on Ubuntu
sudo apt-get install imagemagick
@niraj-shah
niraj-shah / mogrify.sh
Last active December 15, 2015 22:19
Compress images to 1024x1024 if they are larger
# Resize images larger than 1024x1024
sudo mogrify -verbose -resize '1024x1024>' image.jpg
# Resize all images to 1024x1024
sudo mogrify -verbose -resize '1024x1024' image.jpg
# Resize all JPEG images larger than 1024x1024
sudo mogrify -verbose -resize '1024x1024>' *.jpg
@niraj-shah
niraj-shah / mogrify_verbose.sh
Created April 7, 2013 21:45
mogrify with verbose flag
$> sudo mogrify -verbose -resize '1024x1024>' image.jpg
image.jpg JPEG 2592x1944 2592x1944+0+0 8-bit DirectClass 2.395MB 0.110u 0:00.109
image.jpg JPEG 2592x1944=>1024x768 1024x768+0+0 8-bit DirectClass 500KB 0.960u 0:00.950
@niraj-shah
niraj-shah / sql_backup.sh
Last active August 23, 2017 19:33
Amazon S3 Backup Script for MySQL Databases
#!/bin/bash
# Shell script to backup MySql database
# CONFIG - Only edit the below lines to setup the script
# ===============================
MyUSER="root" # USERNAME
MyPASS="password" # PASSWORD
MyHOST="localhost" # Hostname
# Run everday at 2am
0 2 * * * /path/to/sql_backup.sh
@niraj-shah
niraj-shah / fb_share.js
Last active February 8, 2019 09:49
Facebook Feed Callback
function fb_share() {
FB.ui( {
method: 'feed',
name: "Facebook API: Tracking Shares using the JavaScript SDK",
link: "https://www.webniraj.com/2013/05/11/facebook-api-tracking-shares-using-the-javascript-sdk/",
picture: "https://stackexchange.com/users/flair/557969.png",
caption: "Tracking Facebook Shares on your website or application is a useful way of seeing how popular your articles are with your readers. In order to tracking Shares, you must used the Facebook JavaScript SDK."
}, function( response ) {
console.log( response );
if ( response !== null && typeof response !== 'undefined' && typeof response.post_id !== 'undefined' ) {
{
"id": "60506094_10100168488435226",
"from": {
"name": "Niraj Shah",
"id": "60506094"
},
"picture": "http://platform.ak.fbcdn.net/www/app_full_proxy.php?app=134775570045880&v=1&size=z&cksum=70bc38ba261c36e640b74510949a4e2a&src=https%3A%2F%2Fstackexchange.com%2Fusers%2Fflair%2F557969.png",
"link": "https://www.webniraj.com/2013/05/11/facebook-api-tracking-shares-using-the-javascript-sdk/",
"name": "Facebook API: Tracking Shares using the JavaScript SDK",
"caption": "Tracking Facebook Shares on your website or application is a useful way of seeing how popular your articles are with your readers. In order to tracking Shares, you must used the Facebook JavaScript SDK.",
@niraj-shah
niraj-shah / callback.json
Last active December 17, 2015 05:58
Response from Facebook after a 'feed' post
{
"post_id": "60506094_10100168488435226"
}
@niraj-shah
niraj-shah / ajax.php
Created May 11, 2013 21:15
Share Facebook Share (PHP Code Igniter) code
public function save_share() {
$response = array( 'response' => 'true' );
$this->load->model( 'Share_model' );
$meta = $this->input->post('meta');
$insert = array(
'share_type' => $type,
'share_meta' => $meta['post_id'],