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 / sequential.js
Created October 8, 2018 16:18
Sequential Ajax Calls using jQuery
// parameters for ajax calls
var items = [
{ 'gender': 'male', 'nat': 'US' },
{ 'gender': 'female', 'nat': 'GB' }
];
// function to trigger the ajax call
var ajax_request = function(item) {
var deferred = $.Deferred();
@niraj-shah
niraj-shah / eid_regex.php
Last active February 4, 2022 09:46
PHP Regex to validate Emirates ID number
<?php
/**
* Regex example to validate the format of a Emirates
* ID number. Does not validate the checkbit (Luhn Algorithm).
*
* @author Niraj Shah <niraj@webniraj.com>
*/
// regex to validate the format xxx-xxxx-xxxxxxx-x (Emirates ID)
#!/usr/local/bin/php
<?php
// get command line arguments
$args = $argv;
// AbuseIPDB API Key
$api_key = 'xxx';
// your AbuseIPDB User ID
@niraj-shah
niraj-shah / parse_acl.js
Created August 2, 2013 17:44
Two examples of setting ACL controls using Parse JS SDK
// ACL to restrict write to user, and public read access
var custom_acl = new Parse.ACL();
// give write access to the current user
custom_acl.setWriteAccess( Parse.User.current(), true);
// give public read access
custom_acl.setPublicReadAccess(true);
GameObject.setACL(custom_acl);
// ACL to restrict write to user, and no public access
var custom_acl = new Parse.ACL();
@niraj-shah
niraj-shah / parse-pointers.js
Created July 3, 2014 12:39
Parse.com JavaScript SDK - Using Pointers and ACL
// new Profile object
var Profile = Parse.Object.extend("Profile");
var profile = new Profile();
// set DOB as date - needs to be ISO format
var dob = new Date("1985-01-01");
profile.set( 'dob', { "__type": "Date", "iso": dob.toISOString() } );
// bio string data
profile.set( 'bio', 'I am a PHP developer' );
// pointer to User table (parse Classes should have _ prefix.)
@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 / fb_4.0.x.php
Last active September 7, 2019 15:56
Facebook PHP SDK 4.0.0 Example
<?php
// include required files form Facebook SDK
require_once( 'Facebook/HttpClients/FacebookHttpable.php' );
require_once( 'Facebook/HttpClients/FacebookCurl.php' );
require_once( 'Facebook/HttpClients/FacebookCurlHttpClient.php' );
require_once( 'Facebook/Entities/AccessToken.php' );
require_once( 'Facebook/Entities/SignedRequest.php' );
@niraj-shah
niraj-shah / debug-signing.properties
Created November 21, 2016 21:14
Debug Build Signing for Cordova
# location of keystore
storeFile=/path/to/app.keystore
# Key alias
keyAlias=alias_name
# Store password
storePassword=Password1
# Key password
@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' ) {
@niraj-shah
niraj-shah / parse-acl.js
Created July 3, 2014 13:13
Parse.com JavaScript SDK - ACL Examples
// true = access allowed, false = not allowed
// create ACL
var acl = new Parse.ACL();
// public can read
acl.setPublicReadAccess( true );
// public cannot write
acl.setPublicWriteAccess( false );
// user can read data