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
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);
@fordnox
fordnox / RabbitRpc.php
Created June 9, 2015 13:05
RabbitRpc.php
<?php
use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Message\AMQPMessage;
class RabbitRpc
{
const TIMEOUT = 15;
@fordnox
fordnox / latest.html
Created February 27, 2015 09:08
Lastes version of software from github
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div class="container">
<p>
<a href="#" class="release-download btnd btnd-1 btnd-1d">Download</a>
@fordnox
fordnox / fb_friends.py
Created February 25, 2015 20:46
Facebook friends pictures
import requests
import json
import urllib2
import webbrowser
from pprint import pprint
token = ''
api_url = 'https://graph.facebook.com/v2.1/'
params = {'access_token' : token}
@fordnox
fordnox / domain.conf
Created December 13, 2014 08:20
Split clients nginx conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
@fordnox
fordnox / date_range.php
Created November 13, 2014 11:08
Date ranges in PHP
<?php
private function _getDataRange($range)
{
$lowerdate = null;
$upperdate = null;
switch ($range) {
case 'today':
$lowerdate = date('Y-m-d 00:00:00');
Verifying that +putna is my Bitcoin username. You can send me #bitcoin here: https://onename.io/putna
@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);
@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 / 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);
}
});