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 / wp-gist-plugin.php
Last active October 6, 2015 09:48
Wordpress: gist plugin
wp_embed_register_handler( 'gist', '/https:\/\/gist\.github\.com\/(\d+)(\?file=.*)?/i', 'wp_embed_handler_gist' );
function wp_embed_handler_gist( $matches, $attr, $url, $rawattr ) {
$embed = sprintf(
'<script src="https://gist.github.com/%1$s.js%2$s"></script>',
esc_attr($matches[1]),
esc_attr($matches[2])
);
@madeinnordeste
madeinnordeste / PHP-Get-Geocode-from-Address
Last active October 4, 2022 13:30
PHP - Get Geocode (lat, long) from Address
<?php
$address = 'avenida+gustavo+paiva,maceio,alagoas,brasil';
$geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$address.'&sensor=false');
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;
@madeinnordeste
madeinnordeste / JS-FightCode-robot.js
Last active October 13, 2015 14:08
madeinnordeste
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(180);
robot.rotateCannon(360);
@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(
@madeinnordeste
madeinnordeste / PHP-Text-URL-to-Hyperlink.php
Last active April 27, 2022 20:08
PHP - Transform text URL to Hyperlink
<?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-Remove-URL-from-string.php
Created May 3, 2014 00:56
PHP - Remove URLs from string
<?php
$string = 'Hi, visit my website: http://beto.euqueroserummacaco.com';
$string = preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', '', $string);
echo $string;
?>
@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 ;) ');