Skip to content

Instantly share code, notes, and snippets.

View ruslanchek's full-sized avatar
🎯
Focusing

Mike Burton ruslanchek

🎯
Focusing
View GitHub Profile
@ruslanchek
ruslanchek / core.js
Last active December 20, 2015 10:20
Очеловечивание времени - выводит дату в человеческом формате (27 июля, 2013, 21:00:15). Работает как со строками вида MySQL Timestamp, так и с простым объектом Date.
function humanizeDate(date, output_with_time) {
if(!(Object.prototype.toString.call(date) === "[object Date]")){
var t = date.split(/[- :]/);
date = new Date(t[0], t[1] - 1, t[2], t[3], t[4], t[5]);
}
if (!date) {
return '—';
}
@ruslanchek
ruslanchek / nodejs
Created September 24, 2012 13:02
node.js init.d script for CentOS
#!/bin/sh
#
# chkconfig: 35 99 99
# description: Node.js /home/nodejs/sample/app.js
#
. /etc/rc.d/init.d/functions
USER="nodejs"
@ruslanchek
ruslanchek / antiddos.php
Created August 5, 2012 21:42
Litle DDoS hack :-)
<?PHP
if((!isset($_COOKIE) || !isset($_GET['r'])) || $_GET['r'] != $_COOKIE['r']){
$rnd = md5(mt_rand());
if($_SERVER['QUERY_STRING'] && !$_GET['r']){
$s = '?' . $_SERVER['QUERY_STRING'] . '&r='.$rnd;
}else{
$s = '?r='.$rnd;
};
<?php
function showOAuthError($error, $error_description){
if($error == 'access_denied'){
header("Location: http://".$_SERVER['HTTP_HOST']);
}else{
$error = '<strong>Error: '.$error.'</strong>
<p>'.preg_replace('/\+/', ' ', $error_description).'</p>';
die($error);
};