Skip to content

Instantly share code, notes, and snippets.

View mishak87's full-sized avatar

Michal Gebauer mishak87

View GitHub Profile
@mishak87
mishak87 / dump.php
Created December 2, 2011 14:38
Fast dump for debugging
<?php
@mkdir('/tmp/debugging', 02755, true);
file_put_contents('/tmp/debugging/event.log', print_r(array($_SERVER, $_POST, $_GET, $_SESSION), true));
@mishak87
mishak87 / FacebookPresenter.php
Created May 5, 2012 17:31
Fix for facebook was not playing along with nette sessions
<?php
namespace UserModule;
use FixFacebook;
class FacebookPresenter extends AbstractSignPresenter
{
public function actionLogin()
@mishak87
mishak87 / build_css.php
Created May 6, 2012 11:29
Builds css from sass and css files - using Nette conventions for directory structure
<?php
$documentRootStyles = realpath(__DIR__ . '/../document_root/css');
$appDir = realpath(__DIR__ . '/../app');
foreach (new DirectoryIterator($appDir) as $file) {
if (!$file->isDir() || !preg_match('/.+Module/', $file->getFilename())) {
continue;
}
$module = lcfirst(substr($file->getFilename(), 0, -6));
$stylesDir = $appDir . '/' . $file->getFilename() . '/styles';
@mishak87
mishak87 / Router.php
Created May 24, 2012 12:01
Router for API REST like methods
<?php
namespace ApiModule;
use Nette,
Nette\Application\Request;
class Router extends Nette\Object implements Nette\Application\IRouter
{
@mishak87
mishak87 / php
Created August 26, 2012 13:11
Nginx - PHP https painless setup
location ~ \.php {
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
@mishak87
mishak87 / exponential_backoff.php
Created September 25, 2012 20:56
Exponential backoff
$stopAt = 15; // 4h 33m 4s
$now = new DateTime;
?><table><?php
foreach (range(1, 15) as $i) {
?><tr><td><?php
echo $i
?><td><?php
$after = clone $now;
$tries = min($i, $stopAt);
$seconds = (int) ceil( (pow(2, $tries) - 1) / 2 );
@mishak87
mishak87 / conver.php
Created December 21, 2012 20:04
Simple script for converting Nette templates file structure from <Presenter>.<action>.phtml or .latte to <Presenter>/<action>.latte
<?php
$root = ltrim(getcwd(), DIRECTORY_SEPARATOR);
foreach (scandir($root) as $file) {
if (preg_match('/^(?P<presenter>[^.]+)\.(?P<action>[^.]+)\.(latte|phtml)$/', $file, $matches)) {
$dir = $root . DIRECTORY_SEPARATOR . $matches['presenter'];
$filename = $dir . DIRECTORY_SEPARATOR . $matches['action'] . '.latte';
if (!is_dir($dir)) {
mkdir($dir);
}
@mishak87
mishak87 / BirthNumber.cs
Last active May 6, 2021 07:42
C# class for simple checking of birth number validity with some useful parameters. C# třída pro práci a validaci rodného čísla s pár užitečnými parametry.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Runtime.Serialization;
namespace net.mishak.utils
{
@mishak87
mishak87 / crypsy-chat-ignore.js
Created July 14, 2013 04:28
Ignore people in chat
var blacklist = ['mishak','mullick'];
setInterval(function () {
$('#chatcontent > div').each(function(i,v){if(-1!=$.inArray($('span', v).text(), blacklist))$(v).hide();});
}, 1000);
<?php
namespace ApiModule;
use Api\Authenticator,
Model\Rest,
Model\Action,
Mishak\Application\Response\JsonResponse,
Nette,
Nette\Application\UI\Presenter,