Skip to content

Instantly share code, notes, and snippets.

View anunay's full-sized avatar
🏠
Working from home

Anunay Dahal anunay

🏠
Working from home
View GitHub Profile
@anunay
anunay / query-string-fetcher.js
Last active November 20, 2019 03:49
Javascript: Query String Fetcher, URL Params, URL Parameters
function urlParam(name, w){
w = w || window;
var rx = new RegExp('[\&|\?]'+name+'=([^\&\#]+)');
var val = w.document.URL.match(rx);
return !val ? '':val[1];
}
@anunay
anunay / js-email-validator.js
Last active July 25, 2016 04:51
Javascript: Email Validator
/**
* function validateEmail(email){}
* @author Anunay Dahal
* @param String email [Email address as a parameter]
* @return Boolean [Returns TRUE if email address is valid else return FALSE]
*/
function validateEmail(email){
return /^([\w!.%+\-])+@([\w\-])+(?:\.[\w\-]+)+$/.test(email);
}
@anunay
anunay / jwplayer-rtmp-streaming.html
Created April 4, 2013 11:01
Javascript: JWPlayer RTMP Streaming Sample Code
<script type='text/javascript'>
jwplayer("PLAYER_ID").setup({
flashplayer: "/jwplayer/player.swf",
controlbar: "bottom",
dock:false,
file: "AUDIO/VIDEO FILENAME",
streamer: "rtmp://STREAMING-DISTRIBUTION-DOMAIN-NAME/cfx/st",
width: "162",
height: "24",
});
<?php
if ( ! function_exists('product_post_type') ) {
// Register Custom Post Type
function product_post_type() {
$labels = array(
'name' => _x( 'Products', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Product', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Product', 'text_domain' ),
'parent_item_colon' => __( 'Parent Product:', 'text_domain' ),
@anunay
anunay / JWPlayer6.0-RTMP-Streaming.js
Created April 12, 2013 22:13
Solved RTMP Streaming in JWPlayer 6
/*
*
* The "streamer/file" setup you are using is used by
* an older version of JW Player (JW5), but not by the
* latest version (JW6). We're still going back and forth
* with Cloudfront to update their docs...
*
* Anyway, setting the RTMP stream with just a single "file"
* will work for JW6:
*
@anunay
anunay / modsecurity-whitelist.conf
Last active December 9, 2022 14:08
Whitelist IP in ModSecurity (whitelist.conf)
##Whitelist IP in ModSecurity
#1. If you need to whitelist an IP in ModSecurity (v2.7+), here’s what to do:
nano /usr/local/apache/conf/modsec2/whitelist.conf
#2. add this line, replacing (#####) with a unique ID number for mod security, I used a version of my whitelisted ip address:
SecRule REMOTE_ADDR "@ipMatch 1.2.3.4" "phase:1,t:none,nolog,allow,ctl:ruleEngine=Off,ctl:auditEngine=Off,id:(#####)"
#3. Then restart apache.
@anunay
anunay / RedirectScript.php
Created June 3, 2013 10:21
RedirectScript.php
<?php
/*Optional Paramter SKIPTO to redirect to some other upsell page */
if(isset($_REQUEST['skip']) && @$_REQUEST['skip'] == "true" ){
header("Location: " . $skipto);
exit;
}
@anunay
anunay / php-string-to-slug.php
Created June 12, 2013 22:58
PHP Convert String to Slug
<?php
function to_slug($string){
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string)));
}
// Input: This is Headline
// Returns: this-is-headline
@anunay
anunay / php-replace-non-alpha-chars.php
Created June 12, 2013 23:01
PHP: Strip Non-Alphanumeric Chars from a String
<?php
$string = preg_replace("/[^a-z0-9]+/i", "", $string);
@anunay
anunay / php-make-clickable.php
Created June 12, 2013 23:11
PHP: Make Clickable
<?php
/**
* Supports normal, ftp, file and email URL’s as well as subdomains.
* Also it doesn’t mess with HTML a tags that already exist in the string.
*
* @param String $text Contens that needs to be parsed through
* @return String String
*
*/