Skip to content

Instantly share code, notes, and snippets.

View gabrielef's full-sized avatar

Gabriele Formenti gabrielef

  • Cutowl Srl
  • Milan, Italy
View GitHub Profile
@gabrielef
gabrielef / minutesToHoursMinutes.php
Created February 14, 2020 14:14
Convert minutes (also negative) like 200 or -300, in the +/-mm:ss notation (+05:00 or -06:00). Useful when working with timezone.
function convertToHoursMins($time) {
$sign = '+';
if ($time < 0)
$sign = '-';
$time = abs($time);
$hours = floor($time / 60);
$minutes = ($time % 60);
return $sign . sprintf('%02d:%02d', $hours, $minutes);
}
$(document).ready(function () {
var multi = $('#multiscroll').multiscroll({
scrollOverflow: true,
onLeave: function (index, nextIndex, direction) {
//after leaving section 2
var fine = 3;
console.log(index, nextIndex, direction);
},
afterLoad: function (anchorLink, index) {
@gabrielef
gabrielef / lastDayMonthBefore.js
Created September 8, 2016 13:03
Retrieve the last day of the previous month
var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
firstDay.setDate(firstDay.getDate()-1);
console.log(firstDay);
console.log(firstDay.getFullYear() + '-' + (firstDay.getMonth()+1) + '-' + firstDay.getDate());
//fix two char month
var month = firstDay.getMonth()+1;
if(month < 10){
month = '0' + month;
}
@gabrielef
gabrielef / SanitizeUrl.php
Last active June 23, 2017 19:48
Convert title to seo friendly url
<?php
class SanitizeUrl {
public static function slug($string, $space="-") {
$string = utf8_encode($string);
if (function_exists('iconv')) {
$string = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
}
$string = preg_replace("/[^a-zA-Z0-9 \-]/", "", $string);
@gabrielef
gabrielef / redirect.php
Last active December 22, 2015 06:58
Thi script redirect not unauthorized users, for example during maintenance.Put ip address of authorized users inside the $admin array.
<?php
//admins address
$admins = array('97.23.95.1', '192.168.1.74');
//redirect page for unauthorized users
$page = 'http://www.sitename.com/redirectpage.html';
//////////////////////////////////////////////////////////////////////////
//user ip address
$user = $_SERVER['REMOTE_ADDR'];
//user will be redirect to $page if its ip isn't in the $admin array