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 / android4.4_screen_record.sh
Created November 7, 2013 14:16
Screen recording an Android 4.4 device using ADB
# run the adb shell
adb shell
# basic recording from shell
screenrecord --verbose /sdcard/nexus5.mp4
# press Ctrl-C to stop
# recording for 30 seconds
screenrecord --verbose --time-limit 30 /sdcard/nexus5.mp4
@niraj-shah
niraj-shah / facebook_detect.php
Created December 18, 2013 20:57
Checking if Facebook robot is hitting your page
if ( strstr( $_SERVER['HTTP_USER_AGENT'], 'facebookexternalhit' ) {
// show OpenGraph headers for page
} else {
// Password protected page / login page
}
@niraj-shah
niraj-shah / login_form.php
Created January 12, 2014 14:47
CodeIgniter login for with CSRF
# load helper manually
$this->load->helper('form');
# create form
echo form_open( base_url( 'login' ), array( 'id' => 'login-form', 'class' => 'login' ) );
@niraj-shah
niraj-shah / login_form.php
Created January 12, 2014 14:53
CodeIgnitor Form with CSRF token added
<form action="http://testapplication.com/login" method="post" accept-charset="utf-8" id="login-form" class="login">
<div style="display:none">
<input type="hidden" name="csrf_test_name" value="80bfb80b356d6d31f4ce4dad0c6cf69e">
</div>
...
...
</form>
@niraj-shah
niraj-shah / manual_csrf.php
Last active January 3, 2016 00:49
Manual CSRF token in CodeIgniter
<input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">
@niraj-shah
niraj-shah / ajax_csrf.html
Last active January 3, 2016 00:59
Added CSRF token to AJAX calls using JavaScript Variable
<!-- add to HEAD -->
<script type="text/javascript">
var csrf_value = '<?php echo $this->security->get_csrf_hash(); ?>';
</script>
<!-- Update AJAX code, change csrf_test_name as needed -->
<script type="text/javascript">
$.post( ajax_url, { data: 'value', 'csrf_test_name': csrf_value }, function( response ) {
// response
}, 'json' );
@niraj-shah
niraj-shah / ajax_csrf.html
Created January 12, 2014 15:18
Added CSRF token to AJAX calls using Form Serialization
<!-- create form with open_form() -->
<form action="http://testapplication.com/login" method="post" accept-charset="utf-8" id="login-form" class="login">
<div style="display:none">
<input type="hidden" name="csrf_test_name" value="80bfb80b356d6d31f4ce4dad0c6cf69e">
</div>
...
...
</form>
<!-- Update AJAX code to post serialized data -->
@niraj-shah
niraj-shah / wp_menu.php
Last active August 29, 2015 13:56
WordPress Plugin to Customise Toolbar
<?php
/**
* @package MyToolbar
*/
/*
Plugin Name: MyToolbar
Plugin URI: http://www.webniraj.com
Description: This plugin creates a custom toolbar
Version: 1.0
<?php
// remove WordPress items from toolbar
function preload_my_toolbar() {
global $wp_admin_bar;
// remove WordPress logo
$wp_admin_bar->remove_node('wp-logo');
// remove search button
@niraj-shah
niraj-shah / wp_toolbar_complete.php
Created February 17, 2014 15:31
Complete version of custom toolbar plugin
<?php
/**
* @package MyToolbar
*/
/*
Plugin Name: MyToolbar
Plugin URI: http://www.webniraj.com
Description: This plugin creates a custom toolbar
Version: 1.0