Skip to content

Instantly share code, notes, and snippets.

@sotoz
sotoz / getdirections.js
Last active March 2, 2016 09:37
Google maps geolocation get directions
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=123&sensor=false&language=el"></script>
<script>
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom: 9,
mapTypeId: google.maps.MapTypeId.ROADMAP,
@sotoz
sotoz / libxmlerrors.php
Created February 25, 2016 09:24
Show broken xml errors with php
<?php
libxml_use_internal_errors(true);
$sxe = simplexml_load_string("<?xml version='1.0'><broken><xml></broken>");
if ($sxe === false) {
echo "Failed loading XML\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
}
?>
@sotoz
sotoz / inputToUppercase.js
Last active February 1, 2016 11:28
inputToUppercase
function inputUppercase(input)
{
input.bind('keyup', function (e) {
qq = input.val().toUpperCase();
//fix greek accented characters
data = qq.replace(/[ΈΆΌΎΊΉ]/g, function (m) {
return {
'Έ': 'Ε',
@sotoz
sotoz / passgenerator.js
Created January 18, 2016 20:43
auto password generator javascript
// Auto Password Generator
function makePasswd()
{
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 8; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
@sotoz
sotoz / update.sql
Last active January 30, 2016 19:40
Update/Increment a single column on multiple rows at once
SET @a = 0;
UPDATE favorits SET order = @a:=@a+1;
@sotoz
sotoz / datevalidation.php
Created December 14, 2015 12:54
Date validation with php
<?php
function validateDate($date, $format = 'Y-m-d H:i:s')
{
$d = DateTime::createFromFormat($format, $date);
return $d && $d->format($format) == $date;
}
var_dump(validateDate('2012-02-28 12:12:12')); # true
var_dump(validateDate('2012-02-30 12:12:12')); # false
@sotoz
sotoz / socialmedia
Created December 14, 2015 12:54
Social media services share URL’s
Twitter
http://twitter.com/home?status=[TITLE]+[URL]
=====
Digg
http://www.digg.com/submit?phase=2&url=[URL]&title=[TITLE]
=====
Facebook
http://www.facebook.com/share.php?u=[URL]&title=[TITLE]
=====
StumbleUpon
@sotoz
sotoz / singletondb.php
Created December 14, 2015 12:53
Singleton PHP Database connection
<?php
class Connection {
private $uname = "";
private $password = "";
private $host = "localhost";
private $port;
private $database = "";
private static $__instance = NULL;
@sotoz
sotoz / meta.html
Created December 14, 2015 12:51
HTML cache headers
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
@sotoz
sotoz / gmap.html
Last active January 30, 2016 19:39
Google map zoom out bug while scrolling
<!--1. φτιαχνεις εναν holder (gmap-holder) εξω απο το map-canvas που φόρτώνει ο χάρτης.
2. Βαζεις καρφωτο pointer-events:none; στο style του map-canvas (ή με αρχείο css).
3. Με jquery ελεγχεις το κλικ του holder και αφαιρείς το pointer-events στον χαρτη
-->
<div class="gmap-holder">
<div id="map-canvas" style="pointer-events:none;height: 650px;width: 100%;"></div>
</div>
<script>
$(document).ready(function(){