Skip to content

Instantly share code, notes, and snippets.

View gabrieledarrigo's full-sized avatar
😃
Smiling

Gabriele D'Arrigo gabrieledarrigo

😃
Smiling
View GitHub Profile
@gabrieledarrigo
gabrieledarrigo / basic.sql
Created September 6, 2012 07:39
Basic SQL Statements
CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
....
);
SELECT column_name(s)
FROM table_name
@gabrieledarrigo
gabrieledarrigo / gist:3985971
Created October 31, 2012 09:03
class for ftp moving file
<?php
class FileDispatcher {
private $ftpServer = '';
private $ftpUser = '';
private $ftpPassword = '';
private $connection;
private $localFile;
private $remoteFolder;
@gabrieledarrigo
gabrieledarrigo / single-cache.php
Created November 20, 2012 09:04
Simple Caching System for a single file
// Caching system; se il file è meno recente di un ora viene rieseguita la chiamata e il file locale viene sovrascritto.
if (file_exists($filename) && filemtime($filename) > (time() - 60 * 60)) {
$feed = simplexml_load_file('feed.xml', 'SimpleXMLElement', LIBXML_NOCDATA);
} else {
$remoteFile = file_get_contents('http://remotefile.xml');
file_put_contents($filename, $remoteFile, LOCK_EX);
@gabrieledarrigo
gabrieledarrigo / accented_string.php
Created April 2, 2013 14:32
Convert accented charcter
<?php
$str = "una qualsiasi stringa in UTF-8";
$str = trim($str); // elimina spazi all'inizio e alla fine della stringa
$str = strip_tags($str); // elimina i tag HTML
$str = utf8_decode($str); // da UTF-8 a ISO-8859-1
$str = html_entity_decode($str, ENT_QUOTES, "UTF-8"); // decodifica tutti i caratteri in HTML a caratteri semplici, e riporta la stringa in UTF-8
?>
@gabrieledarrigo
gabrieledarrigo / trigger_example.sql
Created May 8, 2013 09:14
An Sql trigger example.
DELIMITER $$
CREATE TRIGGER ai_photogallery AFTER INSERT ON photogallery_item
FOR EACH ROW
BEGIN
UPDATE photogallery_master
SET file =
(SELECT file FROM photogallery_item WHERE id_photogallery = NEW.id_photogallery ORDER BY ordine DESC LIMIT 1)
WHERE id = NEW.id_photogallery;
END;
$$
@gabrieledarrigo
gabrieledarrigo / MemcacheRetriever.php
Created June 7, 2013 08:22
Singleton Pattern applied to a Service of Zend Framework
<?php
/**
* This service return an instance of Zend Cache Manager Plugin.
*
* @author gdarrigo
*/
class Application_Service_MemcacheRetriever {
protected static $_istance = null;
@gabrieledarrigo
gabrieledarrigo / mysql_all_user
Created January 22, 2014 11:55
Select all mysql USER
SELECT user, host
FROM mysql.user;
@gabrieledarrigo
gabrieledarrigo / isPrime.js
Created April 12, 2016 14:52
isPrime function
function isPrime(n) {
if (n === 1) {
return false;
}
if (n === 2) {
return true;
}
const root = Math.floor(Math.sqrt(n));
@gabrieledarrigo
gabrieledarrigo / .hyper.js
Created December 27, 2017 08:31
Hyper Configuration
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// Choose either "stable" for receiving highly polished,
// or "canary" for less polished but more frequent updates
updateChannel: 'stable',
@gabrieledarrigo
gabrieledarrigo / linear-search.md
Last active March 4, 2018 12:54
Linear search exercises

Write a program that takes input of integers N and M, followed by N more integers and then M more integers. For each of the last M numbers, the program outputs true, if that number was present in the array of N numbers, output False otherwise

Constraints: 0 < N < 20,000

0<M<15,000

Your output lines should not have any trailing or leading whitespaces

Input