Skip to content

Instantly share code, notes, and snippets.

View vodolaz095's full-sized avatar

Остроумов Анатолий vodolaz095

View GitHub Profile
@vodolaz095
vodolaz095 / gist:1159273
Created August 20, 2011 16:04
Filter ajax post request with message to cp1251 with code filtering
function filter($a,$ajax=false)
{
/*
*Filter text messages created by ajax post request to mysql insertions, also all malicious tags (scripts, frames et cetera are removed)
*/
if ($ajax) $a=iconv('UTF-8','WINDOWS-1251',urldecode($a));
$a=trim($a);
$a=preg_replace('~<script.*>.*</script>~im',NULL,$a);
@vodolaz095
vodolaz095 / screencast.sh
Last active December 29, 2016 14:46
Simple bash script to record screencast with ffmpeg in high quality to local file
#!/bin/bash
if [ "$1" = '--help' ];then
echo 'Usage ./screencast.sh [filename]'
else
dimensions=`xdpyinfo | grep 'dimensions:'|awk '{print $2}'`
if [ -n "$1" ];then
outFile="$1"
else
outFile="$HOME/out.avi"
fi
@vodolaz095
vodolaz095 / watchdog.sh
Last active November 20, 2022 12:59
watchdog.sh script for checking server running not mine, i stole it)
#!/bin/bash
# Service watchdog script
# Put in crontab to automatially restart services (and optionally email you) if they die for some reason.
# Note: You need to run this as root otherwise you won't be able to restart services.
#
# Example crontab usage:
#
# Strict check for apache2 service every 5 minutes, pipe results to /dev/null
# */5 * * * * sh /root/watchdog.sh apache2 "" > /dev/null
#
@vodolaz095
vodolaz095 / backupAndUpload.sh
Created March 2, 2013 20:21
Upload MySQL database to YandexDisk
DATE=`date +%Y-%m-%d--%H-%M-%S`
YaDiskLogin="myName@yandex.ru"
yaDiskPassword="myPass"
MySQLLogin="root"
MySQLPassword="SecReT"
MySQLDB="MyDB"
@vodolaz095
vodolaz095 / print.js
Last active August 30, 2023 20:47
Print for NodeJS using CUPS backend
var ipp = require('ipp'); //get it from there - https://npmjs.org/package/ipp - $npm install ipp
var request = require('request'); //get it from there - https://npmjs.org/package/request - $npm install request
var fs = require('fs');
function getPrinterUrls(callback) {
var CUPSurl = 'http://localhost:631/printers';//todo - change of you have CUPS running on other host
request(CUPSurl, function (error, response, body) {
if (!error && response.statusCode == 200) {
var printersMatches = body.match(/<TR><TD><A HREF="\/printers\/([a-zA-Z0-9-^"]+)">/gm);//i know, this is terrible, sorry(
var printersUrls = [];
@vodolaz095
vodolaz095 / gist:5939316
Created July 6, 2013 09:01
nodejs - mysql - json
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'example.org',
user : 'bob',
password : 'secret',
});
connection.query('SELECT * FROM `tbl` ORDER BY `id` DESC', function(err, rows) {
console.log(JSON.stringify(rows));
});
@vodolaz095
vodolaz095 / mem.js
Created August 10, 2013 17:15
NodeJS modules are singletons
//A memory cache client for nodeJS
//It leaks memory and not scalable, DO NOT USE IN PRODUCTION!
//2 methods are utilized
// .get(key,function(err,value){})
// .set(key,value,function(err,resultOfSaving){},timeToLiveInMilliseconds)
var Storage = {};
exports.get = function (key, callback) {
if (Storage[key]) {
@vodolaz095
vodolaz095 / index.js
Created September 4, 2013 09:40
expressJS example for waterfall style routing
var express = require('express');
var app = express();
app.get('/', function(req, res){
res.send('hello world, this is route 1');
});
app.get('/', function(req, res){
res.send('hello world, this is route 2');
});
@vodolaz095
vodolaz095 / gist:6437416
Created September 4, 2013 14:07
Unpack all archives by 1 command
#.bashrc
# Command «unpack»
unpack ()
{
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.tar.xz) tar xvJf $1 ;;
*.bz2) bunzip2 $1 ;;
@vodolaz095
vodolaz095 / Pound.cfg
Last active December 27, 2015 20:28
Pound.cfg
User "pound"
Group "pound"
LogLevel 0
LogFacility -
Alive 1
TimeOut 10
ListenHTTP
Address 0.0.0.0
xHTTP 1