Skip to content

Instantly share code, notes, and snippets.

@sotoz
sotoz / fetchimage.php
Created December 14, 2015 12:50
Fetch image with php
private function grab_image($url,$saveto)
{
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$raw=curl_exec($ch);
curl_close ($ch);
if(file_exists($saveto)){
@sotoz
sotoz / sessionfix.php
Created December 14, 2015 12:50
Session fix for codeigniter
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once BASEPATH . '/libraries/Session.php';
class MY_Session extends CI_Session
{
function __construct()
{
parent::__construct();
$this->CI->session = $this;
}
@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(){
@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 / 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 / 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 / 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 / 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 / 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 / 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 {
'Έ': 'Ε',