Skip to content

Instantly share code, notes, and snippets.

View devuri's full-sized avatar

uri devuri

  • Mexico
View GitHub Profile
<?php
/**
* Convert a comma separated file into an associated array.
* The first row should contain the array keys.
*
* Example:
*
* @param string $filename Path to the CSV file
* @param string $delimiter The separator used in the file
* @param boolean $asHash Use header row as keys in the returned array
@devuri
devuri / basichook.php
Created September 7, 2017 11:13 — forked from danielpataki/basichook.php
Getting Started With Plugins
function my_tracking_code() {
echo 'Paste tracking code from Google Analytics here';
}
add_action( 'wp_footer', 'my_tracking_code' );
@devuri
devuri / unzip-this-file.php
Created September 23, 2017 16:02
Unzip a file used this as a utility not for production
<?php
$zip = new ZipArchive;
if(isset($_POST['submit'])){
$zip->open('zipfile.zip');
$zip->extractTo('./');
$zip->close();
}
@devuri
devuri / .htaccess
Created October 2, 2017 11:44
Deny access to the login page and return a 404 add this to .htaccess
#secure the login page
ErrorDocument 403 /path-dummy-returns404/index.php?error=404
<Files wp-login.php>
order deny,allow
Deny from all
# Allow this IP address
allow from 123.123.444.44
</Files>
@devuri
devuri / fix_uppercase.php
Last active October 2, 2017 19:56
Upper Caser converts the first character of each word in a string to uppercase
<?php
//string to lowercase
$text = strtolower('HELLO WORLD');
//converts the first character of each word in a string to uppercase
echo ucwords($text);
@devuri
devuri / function-with-optional-parameters.php
Created October 7, 2017 13:30
function with optional parameters
<?php
if ( empty($f_ar[1]) ) $f_ar[1] = 'date';
@devuri
devuri / Set-value-if-not-exist.php
Last active October 7, 2017 13:41
Function Set value if not exist
<?php
//input @param $var : empty variable (string); @param $new_var (set new variable)
function empty_var($var,$new_var){
if ( empty($var) ) $var = $new_var;
return $var;
}
// credits https://gist.github.com/JeffreyWay/3194444
@devuri
devuri / set-value.md
Created October 7, 2017 13:37 — forked from JeffreyWay/set-value.md
PHP: Set value if not exist

You know how, in JavaScript, we can set a value to a variable if one doesn't, like this:

name = name || 'joe';

This is quite common and very helpful. Another option is to do:

name || (name = 'joe');
@devuri
devuri / play.md
Last active October 9, 2017 12:30
Youtube Playlist

[510-pop]PL2HEDIx6Li8jqhOAi7wQb18wXQ3oeLAO8 [150-urban-pop]PL4o29bINVT4GjAQ-X5D0d34p8V99NFPF8 [1,100-hiphop]PLHmhZG6IDkRAyFay7Nzoy3YE7QLUbQVu3 [305-mtvhits]PLsDLZYdI9YpaLHCOJ0LHh3uP5ZqC3ArQx

@devuri
devuri / foolproof.md
Created October 9, 2017 14:19
fool·proof

adjective adjective: foolproof; adjective: fool-proof

incapable of going wrong or being misused.

"a foolproof security system"