Skip to content

Instantly share code, notes, and snippets.

View turtlix's full-sized avatar
:octocat:

Andri Andreas Priyanto turtlix

:octocat:
View GitHub Profile
// With JavaScript
var text = text.replace(/\s(?=[^\s]*$)/g, ' ');
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
green='\033[0;32m'
@turtlix
turtlix / mysql2sqlite.sh
Last active August 29, 2015 14:26 — forked from esperlu/mysql2sqlite.sh
MySQL to Sqlite converter
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
<?php
function nowuk(){
return date('d/m/Y', time());
}
<?php
$originalDate = "2010-03-21";
$newDate = date("d-m-Y", strtotime($originalDate));
<?php
function weeknumber($ddate){
$date = new DateTime($ddate);
return $date->format("W");
}
<?php
function convertToHoursMins($time, $format = '%02d:%02d') {
if ($time < 1) {
return;
}
$hours = floor($time / 60);
$minutes = ($time % 60);
return sprintf($format, $hours, $minutes);
}
<?php
function dateDiff($date1, $date2){
$datetime1 = new DateTime($date1);
$datetime2 = new DateTime($date2);
$interval = $datetime1->diff($datetime2);
return $interval->format('%H:%I');
}
<?php
if(strtotime(dateString) > time()) {
# date is in the future
}
if(strtotime(dateString) < time()) {
# date is in the past
}
<?php
function age($date){
$time = strtotime($date);
if($time === false){
return '';
}
$year_diff = '';
$date = date('Y-m-d', $time);