Skip to content

Instantly share code, notes, and snippets.

View hpatoio's full-sized avatar
:shipit:

Simone Fumagalli hpatoio

:shipit:
View GitHub Profile
@hpatoio
hpatoio / gist:4100664
Created November 17, 2012 22:09
Convert unix timestamp to date in MsSQL
SELECT dateadd(ss, {field_name}, '19700101') FROM {your_table}
@hpatoio
hpatoio / gist:4100670
Created November 17, 2012 22:12
Get last day of the month in Ruby
last_day_of_the_month = (Date.parse(year_to_process + "-" + (month_to_process.to_i + 1).to_s + "-01") - 1).mday().to_s rescue "31"
@hpatoio
hpatoio / gist:4100680
Created November 17, 2012 22:14
Replace double quote with single quote
UPDATE {table_name} SET {field_name} = REPLACE( {field_name} ,'\"',"")
@hpatoio
hpatoio / gist:4100751
Created November 17, 2012 22:25
Mondey first in Movable Type
my $pad_start = wday_from_ts($y, $m, 1);
my $pad_end = 6 - wday_from_ts($y, $m, $days_in_month);
@hpatoio
hpatoio / gist:4100755
Created November 17, 2012 22:26
Moday first in Movable Type
my $pad_start_tmp = wday_from_ts($y, $m, 1);
my $pad_start = ($pad_start_tmp == 0) ? 6 : $pad_start_tmp - 1;
my $pad_end = wday_from_ts($y, $m, $days_in_month) + 1;
server {
listen 80;
server_name www.yourdomain.com
## root
root /path/to/your/document_root/;
## global rewrites
@hpatoio
hpatoio / gist:4398399
Last active March 15, 2021 02:46
Create a MySQL database and create a user with all grant on it
CREATE USER 'DB_USERNAME'@'localhost' IDENTIFIED BY 'DB_PASSWORD';
GRANT USAGE ON * . * TO 'DB_USERNAME'@'localhost' IDENTIFIED BY 'DB_PASSWORD' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
CREATE DATABASE IF NOT EXISTS `DB_USERNAME` ;
GRANT ALL PRIVILEGES ON `DB_USERNAME` . * TO 'DB_USERNAME'@'localhost';
#For connection from everywhere
GRANT USAGE ON * . * TO 'DB_USERNAME'@'%' IDENTIFIED BY 'DB_PASSWORD' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0
GRANT ALL PRIVILEGES ON `DB_USERNAME` . * TO 'DB_USERNAME'@'%';
security:
providers:
chain_provider:
chain:
providers: [in_memory, fos_userbundle]
in_memory:
memory:
users:
foo: { password: test }
fos_userbundle:
@hpatoio
hpatoio / gist:4662612
Last active December 11, 2015 21:28
composer.json that let you have Symfony bounded to the latest 2.1 stable version but still be able to install other bundles with dev stability
{
"name": "symfony/framework-standard-edition",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-0": { "": "src/" }
},
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.1.*@stable",
@hpatoio
hpatoio / HpatoioForcepassupdateListener.php
Last active June 26, 2018 15:58
Event listener to force FOS user to change password
<?php
namespace Hpatoio\UserBundle\EventListener;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\HttpFoundation\Session\Session;