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 / moment_tz_examples.js
Last active November 21, 2016 22:03
Timezone support using Moment.js
// get the user's timezone
var tz = moment.tz.guess();
console.info('Timezone: ' + tz);
// returns: Timezone: Europe/London
// set the default user timezone
moment.tz.setDefault(tz);
// set custom timezone
moment.tz.setDefault('America/Los_Angeles');
@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 / certificate_pdf.php
Created September 12, 2016 20:36
Creating a PDF using FPDF and PHP
<?php
// include composer packages
include "vendor/autoload.php";
// Create new Landscape PDF
$pdf = new FPDI('l');
// Reference the PDF you want to use (use relative path)
$pagecount = $pdf->setSourceFile( 'certificate.pdf' );
@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 <[email protected]>
*/
// regex to validate the format xxx-xxxx-xxxxxxx-x (Emirates ID)
@niraj-shah
niraj-shah / MyController.php
Created March 8, 2016 09:30
Putting Laravel Validation into a Controller
<?php namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Input;
use Auth;
use View;
use Session;
use Validator;
use Redirect;
@niraj-shah
niraj-shah / release-signing.properties
Last active September 10, 2017 02:05
Create the release-signing.properties file in the platforms/android folder to setup Release Signing
# location of keystore
storeFile=/path/to/app.keystore
# Key alias
keyAlias=alias_name
# Store password
storePassword=Password1
# Key password
@niraj-shah
niraj-shah / startswith.php
Last active February 19, 2016 12:26
Laravel 5.x Custom Validation Rule: startswith
// validate that mobile number starts with '07'
$rules = [
'mobile' => 'required|numeric|startswith:07',
];
// custom validator called startswith
Validator::extend('startswith', function( $attribute, $value, $parameters ) {
return substr( $value, 0, strlen( $parameters[0] ) ) == $parameters[0];
});
@niraj-shah
niraj-shah / password_validator.php
Last active February 19, 2016 12:26
Laravel 5.x Custom Validation Rules
// Remember to include the required classes, e.g. Hash, Validator, Redirect, User model
// define validation rules, 'password' will be our custom rule
$rules = [
'current_password' => 'required|password',
'password' => 'required|confirmed|min:6',
];
// custom rule for 'password'
Validator::extend('password', function( $attribute, $value, $parameters ) {
@niraj-shah
niraj-shah / using_mongo.sh
Created February 1, 2016 10:52
MongoDB Commands
# Start MongoDB Shell
mongo
# Get MongoDB version
mongo --version
# Show Mongo Databases (from MongoDB Shell)
show dbs
# Create DB `parse` and Insert Data to `users` collection
@niraj-shah
niraj-shah / install_mongo.sh
Created February 1, 2016 10:30
Update APT to get latest MongoDB packages and instal latest version of software
# Import the Public Key for Official MongoDB Repo
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
# Update apt-get to get latest MongoDB packages
echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
# Update apt-get package list with new repo details
sudo apt-get update
# Install the latest version of MongoDB