Skip to content

Instantly share code, notes, and snippets.

View fordnox's full-sized avatar
🍕
Eating pizza

Andrius Putna fordnox

🍕
Eating pizza
View GitHub Profile
@fordnox
fordnox / WebHook.php
Created December 3, 2012 13:07
WebHook notifier class
<?php
class WebHookEvent
{
private $name = null;
private $params = array();
public function setName($event)
{
$this->name = $event;
@fordnox
fordnox / gist:5284078
Created April 1, 2013 09:55
pear add-ons
#http://pear.phpunit.de/
sudo pear install phpunit/PHP_Invoker
sudo pear install phpunit/PHPUnit_Selenium
sudo pear install phpunit/PHPUnit_Story
@fordnox
fordnox / SLDs-array.php
Created April 10, 2013 07:21
Get array of all second-level-domains
<?php
$CsvString = file_get_contents('https://raw.github.com/gavingmiller/second-level-domains/master/SLDs.csv');
$Data = str_getcsv($CsvString, PHP_EOL);
foreach($Data as &$Row) {
list($tld, $stld) = str_getcsv($Row, ",");
$Row = $stld;
}
var_export($Data, true);
@fordnox
fordnox / update.sh
Created April 22, 2013 16:57
sh script to update repository in current folder
#!/bin/sh
git reset --hard HEAD
git pull
git submodule update --init
<?php
/**
* BoxBilling
*
* LICENSE
*
* This source file is subject to the license that is bundled
* with this package in the file LICENSE.txt
* It is also available through the world-wide-web at this URL:
* http://www.boxbilling.com/LICENSE.txt
@fordnox
fordnox / proxy.py
Created March 21, 2014 08:04
python proxy
#!/usr/bin/python
import json
from subprocess import Popen, PIPE
txt = raw_input();
cmd = txt.split()
o = None
e =None
try:
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
@fordnox
fordnox / 1fh.vcl
Last active August 29, 2015 13:59
Most simple varnish VCL /etc/varnish/1fh.vcl
backend default {
.host = "127.0.0.1"; # IP address of your backend (Apache, nginx, etc.)
.port = "8080"; # Port your backend is listening on
}
sub vcl_recv {
# Set the URI of your system directory
if (req.request == "POST" || req.http.X-Requested-With == "XMLHttpRequest")
{
@fordnox
fordnox / bootstrap.php
Created May 17, 2014 09:52
PHP snippet to throw exceptions instead of fatal errors
<?php
register_shutdown_function(function() {
$error = error_get_last();
$message = $error['message'];
if ($error['type'] == 64 && !empty($message)) {
throw new Exception($message);
}
});
@fordnox
fordnox / fb.js
Created June 29, 2014 11:09
One time popup jQuery with facebook like page
$(document).ready(function() {
function rC(nam) {var tC = document.cookie.split('; '); for (var i = tC.length - 1; i >= 0; i--) {var x = tC[i].split('='); if (nam == x[0]) return unescape(x[1]);} return '~';}
function wC(nam,val) {document.cookie = nam + '=' + escape(val);}
function lC(nam,pg) {var val = rC(nam); if (val.indexOf('~'+pg+'~') != -1) return false; val += pg + '~'; wC(nam,val); return true;}
function firstTime(cN) {return lC('meskuciobatonelis',cN);}
function thisPage() {var page = location.href.substring(location.href.lastIndexOf('\/')+1); pos = page.indexOf('.');if (pos > -1) {page = page.substr(0,pos);} return page;}
if (firstTime(thisPage())) {
$('<div>')
@fordnox
fordnox / execute.php
Last active September 16, 2020 07:48
Execute shell command with timeout and converting stderr to Exception if any
<?php
/**
* @param int $timeout - max process execution time in seconds until it is terminated
**/
function execute($cmd, $stdin = null, $timeout = 600)
{
$this->log->debug("executing: " . $cmd . " ". $stdin);
$cmd = str_replace("\n", "", $cmd);
$cmd = str_replace("\r", "", $cmd);