Skip to content

Instantly share code, notes, and snippets.

<?php
$router = new \Phalcon\Mvc\Router(false);
$router->removeExtraSlashes(true);
$router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI);
$api = new \Phalcon\Mvc\Router\Group();
$api->setPrefix('/api/1');
$api->addOptions('/{controller}', array('action' => 'options', 'namespace' => 'Api\V1'));
<?php
function resizeImage($source, $dest, $new_width, $new_height, $quality)
{
// Taken from http://salman-w.blogspot.com/2009/04/crop-to-fit-image-using-aspphp.html
$image = new Phalcon\Image\Adapter\GD($source);
$source_height = $image->getHeight();
$source_width = $image->getWidth();
$source_aspect_ratio = $source_width / $source_height;
$desired_aspect_ratio = $new_width / $new_height;
if ($source_aspect_ratio > $desired_aspect_ratio) {
@serebro
serebro / aaencode
Created December 14, 2014 14:53
Encode any JavaScript program to Japanese style emoticons (^_^)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xml:lang="ja" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="ja" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>aaencode - Encode any JavaScript program to Japanese style emoticons (^_^)</title>
CREATE TYPE address AS (country text, city text, zip varchar(6), street text, number text, building text);
CREATE TABLE users (id SERIAL PRIMARY KEY, email text, adresses address[]);
INSERT INTO users(email, adresses) VALUES('[email protected]', ARRAY[ROW('RU', 'Moscow', '123123', 'Lenina', '5', 'a')::address, ROW('RU', 'SPB', '123456', 'Gagarina', '102', '5')::address]);
SELECT * FROM users;
<?php
// PHP PThreads issue 329 diagnostic script by John Wellesz
// Also a nice example of shared object management...
const ONEMUSEC = 1000000;
printf('file age: %d', time() - filemtime(__file__));
echo PHP_EOL;
@serebro
serebro / ReadMe.md
Created November 10, 2015 00:09 — forked from mattmccray/Loot-ReadMe.md
Loot.js - Smart stores for Riot (like flux, based on ideas from RiotControl)

Loot.js!

Smart stores for Riot (like flux, based on ideas from RiotControl)

Small (<1.5Kb) flux-like store container.

Example

Make sure loot.js is included in your page after riot.js:

@serebro
serebro / backupMongo_bucket.sh
Created September 13, 2016 00:02 — forked from njadhav1/backupMongo_bucket.sh
Backup MongoDB collection and upload to AWS s3
#!/bin/bash
########
# Purpose :- To take a backup of MongoDB Collections and upload to AWS s3
# Requirement :- Make Sure Collection.config file is present in /data/Backup/mongodb
# format for Collection.config is db|collection
# For example
# db1|collections1