Skip to content

Instantly share code, notes, and snippets.

@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
@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:

<?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;
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('user1@example.org', ARRAY[ROW('RU', 'Moscow', '123123', 'Lenina', '5', 'a')::address, ROW('RU', 'SPB', '123456', 'Gagarina', '102', '5')::address]);
SELECT * FROM users;
@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>
<?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) {
<?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'));
@serebro
serebro / Url.php
Last active August 29, 2015 14:05
Generate Phalcon URL with GET params
<?php
class Url extends \Phalcon\Mvc\Url
{
/**
* Generates a URL with GET params
*
* <code>
*
@serebro
serebro / array_find.php
Created August 19, 2014 14:11
array_find
/**
* @return mixed or false
*/
function array_find($array, $fn) {
$next = current($array);
while ($next) {
$key = key($array);
if (call_user_func_array($fn, [$next, $key])) {
return $next;
}
@serebro
serebro / Censure.php
Last active October 29, 2023 10:28
Censure.php
<?php
/**
* Определение наличия мата (нецензурных слов) в тексте, матотест
*
* Алгоритм достаточно надёжен и быстр, в т.ч. на больших объёмах данных
* Метод обнаружения мата основывается на корнях и предлогах русского языка, а не на словаре
* Слова "лох", "хер", "залупа", "сука" матерными словами не считаются (см. словарь Даля)
* Разработка ведётся с 2005 года
*
* Класс явл. хорошим учебным пособием по изучению регулярных выражений и... русского мата! =)