Skip to content

Instantly share code, notes, and snippets.

View madeinnordeste's full-sized avatar
:octocat:
Coding

Luiz Alberto S. Ribeiro madeinnordeste

:octocat:
Coding
View GitHub Profile
@madeinnordeste
madeinnordeste / JS-base-url.js
Last active August 29, 2015 14:00
Javascript - Base URL
function get_settings() {
var doc_location = document.location.href;
var url_strip = new RegExp("http:\/\/.*\/");
var base_url = url_strip.exec(doc_location);
var settings = { "base_url" : base_url }
return settings;
}
settings = get_settings();
alert(settings.base_url);
@madeinnordeste
madeinnordeste / PHP-Gmail-new-messages.php
Last active August 29, 2015 14:00
PHP - Get Gmail new messages (unread) from Atom Feed
<?php
//PHP - Get Gmail new messages (unread) from Atom Feed
$username = urlencode('my-gmail-account');
$password = 'my-password';
$tag = '';
$handle = curl_init();
$options = array(
<?php
$date_a = strtotime('2010-11-25');
$date_b = strtotime('2012-11-25');
if($date_a >= $date_ab{
echo 'date_a >= date_b';
}else{
echo 'date_a < date_b';
}
@madeinnordeste
madeinnordeste / PHP-Geocode-distance.php
Created May 3, 2014 00:54
PHP - Calculate distance between points (Geocode)
<?php
function distance($lat1, $lon1, $lat2, $lon2, $unit) {
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
@madeinnordeste
madeinnordeste / PHP-Convert-string-to-slug.php
Created May 3, 2014 00:57
PHP - Convert string to slug
<?php
function slug($str){
$str = strtolower(trim($str));
$str = preg_replace('/[^a-z0-9-]/', '-', $str);
$str = preg_replace('/-+/', "-", $str);
return $str;
}
echo slug('This is my string ;) ');
@madeinnordeste
madeinnordeste / PHP-parse-CSV.php
Created May 3, 2014 01:00
PHP - Parse CSV files
<?php
$fh = fopen("contacts.csv", "r");
while($line = fgetcsv($fh, 1000, ",")) {
echo "Contact: {$line[1]}";
}
?>
@madeinnordeste
madeinnordeste / PHP-get-emails-from-string.php
Created May 3, 2014 01:06
PHP - Get emails address from string
<?php
function extract_emails($str){
$regexp = '/([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+/i';
preg_match_all($regexp, $str, $m);
return isset($m[0]) ? $m[0] : array();
}
$test_string = 'This is a test string...
<?php
$from = new DateTime('0000-00-00 00:00:00');
$to = new DateTime('now');
$interval = $to->diff($from);
//2011 years, 4 months, 5 days, 11 hours, 13 minutes, 49 seconds
echo $interval->format('%Y years, %m months, %d days, %H hours, %i minutes, %s seconds');
?>
@madeinnordeste
madeinnordeste / PHP-dBug.php
Created May 3, 2014 01:10
PHP - dBug function
<?php
/*********************************************************************************************************************\
* LAST UPDATE
* ============
* March 22, 2007
*
*
* AUTHOR
* =============
* Kwaku Otchere
@madeinnordeste
madeinnordeste / PHP-check-if-string-contains-another-string.php
Created May 3, 2014 01:12
PHP - Check if a string contains another string
<?php
function contains($str, $content, $ignorecase=true){
if ($ignorecase){
$str = strtolower($str);
$content = strtolower($content);
}
return strpos($content,$str) ? true : false;
}