Skip to content

Instantly share code, notes, and snippets.

@imposibrus
imposibrus / gist:10465781
Created April 11, 2014 12:45
Accessing line number in V8 JavaScript (Chrome & Node.js)
// from http://stackoverflow.com/questions/11386492/accessing-line-number-in-v8-javascript-chrome-node-js/11386493#11386493
Object.defineProperty(global, '__stack', {
get: function(){
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function(_, stack){ return stack; };
var err = new Error;
Error.captureStackTrace(err, arguments.callee);
var stack = err.stack;
Error.prepareStackTrace = orig;
@imposibrus
imposibrus / install.sh
Last active January 6, 2018 12:13
Install MongoDB PHP driver on Ubuntu 14.04
sudo apt-get install -y php-pear php5-dev
sudo pecl install mongo
sudo sh -c "echo 'extension=mongo.so' > /etc/php5/mods-available/mongo.ini"
sudo ln -s /etc/php5/mods-available/mongo.ini /etc/php5/apache2/conf.d/mongo.ini
sudo service apache2 restart
@imposibrus
imposibrus / main.js
Last active August 29, 2015 14:04
Upload file with $.ajax()
var fd = new FormData();
fd.append('file', $('input[type="file"]')[0].files[0]);
$.ajax({
url: '/photoUpload',
data: fd,
processData: false,
contentType: false,
cache: false,
type: 'POST',
@imposibrus
imposibrus / apache.conf
Last active November 23, 2016 13:36
config files samples
<VirtualHost *:81>
ServerAdmin [email protected]
DocumentRoot /home/ubuntu/www/ft-ru.ru
ServerName ft-ru.ru
ErrorLog ${APACHE_LOG_DIR}/ft-ru.ru.error.log
CustomLog ${APACHE_LOG_DIR}/ft-ru.ru.access.log common
SetEnv ENV "development"
</VirtualHost>
@imposibrus
imposibrus / db.js
Created July 28, 2014 19:15
Node.js MySQL connection pool with node-mysql package
var mysql = require('mysql');
function handleDisconnect(db_config) {
var connection = mysql.createPool(db_config);
connection.on('error', function(err) {
console.error('db error', err, err.code);
if(err.code === 'PROTOCOL_CONNECTION_LOST') {
handleDisconnect(db_config);
@imposibrus
imposibrus / install_supervisor.sh
Created July 30, 2014 14:52
install supervisor
sudo apt-get install python-setuptools
sudo easy_install supervisor
sudo sh -c "echo_supervisord_conf > /etc/supervisord.conf"
@imposibrus
imposibrus / validateEmail.js
Created August 7, 2014 12:28
JS email address validation
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
if(!validateEmail('[email protected]')) {
// alarm!
}
@imposibrus
imposibrus / index.php
Created September 4, 2014 07:53
display all php errors
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
@imposibrus
imposibrus / install_php-fpm.sh
Last active November 23, 2016 13:36
Install php5-fpm on Ubuntu 14.04
#!/bin/bash
sudo apt-get install php5-fpm php5-cgi php5-mcrypt
sudo sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php5/fpm/php.ini
sudo service php5-fpm restart
@imposibrus
imposibrus / app.js
Last active August 29, 2015 14:10
Node.js debug.js with file name and line number
// first: npm i debug --save
// run with DEBUG=worker,worker2 node app.js
var debug = require('./debug')('worker');
debug('worker');
var debug2 = require('./debug')('worker2');
debug2('worker2');