Skip to content

Instantly share code, notes, and snippets.

View fragoulis's full-sized avatar

Yannis Fragoulis fragoulis

View GitHub Profile
@fragoulis
fragoulis / datetime.php
Last active August 29, 2015 14:07
Get current datetime with timezone and microsecond precision
<?php
/**
* Generate datetime with timezone support and microsend precision.
*
* Example:
* ```
* $now = Datetime::now(); // generates YYYY-MM-DDTHH:MM:SS.MMMMMM
* ```
*
@fragoulis
fragoulis / nextId.sql
Created October 6, 2014 10:11
RDBMS: Generate the next auto increment ID
-----------------------------------------------------------------
-- PostgreSQL
--
SELECT last_value, is_called
FROM :sequence
-- If is_called is false, last_value is 1 and the next ID also 1.
-- If is_called is true, the next ID is last_value + 1
@fragoulis
fragoulis / angular-index.html
Created July 31, 2014 18:38
Angular Bootstrap File
<!doctype html>
<html lang="en" ng-app>
<head>
<meta charset="utf-8">
<title>Page Title</title>
<!-- Bootstrap -->
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<!-- FontAwsome -->
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
@fragoulis
fragoulis / Enum.php
Last active August 29, 2015 14:04
PHP Enumeration implementation
<?php
/**
* Enumeration base class.
*
* Clients can implement this to create commonly used enum
* structs with the use of CONSTs.
*
* Example:
* <pre>
@fragoulis
fragoulis / ext.js
Last active August 29, 2015 14:04
Useful functions that could be considered as extentions to Javascript
/**
* Given an Object it returns its length.
* Much like returning the size of an
* associative array.
*
* Usage:
* ```js
* var size = Object.size(myObject);
* ```
*
@fragoulis
fragoulis / SubmitLink.js
Created June 13, 2014 11:45
Enables clients to submit empty POST, PUT and DELETE requests using simple links.
@fragoulis
fragoulis / dropSchema.sh
Created June 10, 2014 13:50
Postgres dropdb/createdb alternative when there is no maintenance database available to connect to
set PGPASSWORD=password psql --host=host --username=username --command="drop schema public cascade;create schema public;" database
@fragoulis
fragoulis / ConsoleCommand.php
Last active January 16, 2018 06:18
Yii very handy console extension for logging timing and progress of an operation with colors and everything :)
<?php
/**
* Copyright 2014 John Fragkoulis
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@fragoulis
fragoulis / unaccent.rules
Last active June 10, 2022 11:19
Postgres unaccent rules for greek characters
À A
Á A
 A
à A
Ä A
Å A
Æ A
à a
á a
â a
@fragoulis
fragoulis / YiiAutoTimestampBehavior.php
Last active August 29, 2015 13:56
Yii behavior that auto detects timestamps and applies custom conversion on their values.
<?php
class MyBehavior extends CActiveRecordBehavior
{
public to='yyyy-MM-dd';
public $from='Y-m-d';
public function beforeSave($event)
{
foreach ($this->owner->tableSchema->columns as $attribute => $column)