Skip to content

Instantly share code, notes, and snippets.

View chriswitko's full-sized avatar

Chris Witko chriswitko

View GitHub Profile
#!/bin/sh
export NODE_ENV=production
/home/virtual/[domain]/.nvm/v0.10.25/bin/node /home/virtual/[domain]/www/apps/production/staging-api/script.js
/**
* Formats mongoose errors into proper array
*
* @param {Array} errors
* @return {Array}
* @api public
*/
exports.errors = function (errors) {
var keys = Object.keys(errors)
function getToken($length) {
$token = "";
$codeAlphabet = "abcdefghijkmnopqrstuvwxyz";
$codeAlphabet.= "0123456789";
for($i=0;$i<$length;$i++){
$token .= $codeAlphabet[crypto_rand_secure(0,strlen($codeAlphabet))];
}
return $token;
}
function crypto_rand_secure($min, $max) {
$range = $max - $min;
if ($range < 0) return $min; // not so random...
$log = log($range, 2);
$bytes = (int) ($log / 8) + 1; // length in bytes
$bits = (int) $log + 1; // length in bits
$filter = (int) (1 << $bits) - 1; // set all lower bits to 1
do {
$rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes)));
$rnd = $rnd & $filter; // discard irrelevant bits
php_value upload_max_filesize 10M
php_value post_max_size 10M
<IfModule mod_rewrite.c>
<IfModule pagespeed_module>
ModPagespeed off
</IfModule>
Options +FollowSymlinks
RewriteEngine On
function agephoto($file, $out) {
$_cookie = "cookie";
file_put_contents($_cookie, "");
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 360);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0.1) Gecko/20100101 Firefox/5.0.1");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
function gen_code_rev($code) {
$strb = "ABCDEFGHKMNPQRSTUVWXYZ23456789";
for ($i=0; $i<8; $i++)
{
for ($j=0; $j<strlen($strb); $j++)
$str[$i][$j] = $strb[($j+$i*5)%strlen($strb)];
}
$sum = 0;
for ($i=0; $i<8; $i++)
@chriswitko
chriswitko / track.js
Created November 11, 2014 09:33
Simple stats tracker
(function () {
var g = {
init: function () {
this.setCookie('_page_cookie', 1, 1);
var a = this.url();
if (a) {
var c = document.getElementsByTagName('script')[0],
d = document.createElement('script');
d.type = 'text/javascript';
d.src = a;
<?php
/**
* Router framework.
*
* @version 1.0
* @author Chris Witko
* @license MIT License
* @copyright 2012 Chris Witko
*/
@chriswitko
chriswitko / sqlclick_directive.js
Created November 11, 2014 10:20
Single click directive for AngularJS
angular.module('szopuje.directives').directive('sglclick', ['$parse', function($parse) {
return {
restrict: 'A',
link: function(scope, element, attr) {
var fn = $parse(attr['sglclick']);
var delay = 300, clicks = 0, timer = null;
element.on('click', function (event) {
clicks++; //count clicks
if(clicks === 1) {
timer = setTimeout(function() {