Skip to content

Instantly share code, notes, and snippets.

View intech's full-sized avatar
🌍
The idea is not to live forever, it is to create something that will

Ivan Zhuravlev intech

🌍
The idea is not to live forever, it is to create something that will
View GitHub Profile
function Parser( text ) {
EventEmitter.call(this);
var parent = this;
this.text = text;
// Счётчик выполненных функций
this.done = 0;
// Проверяем все ли функции выполнены для передачи результата
this.on('done', function(where) {
// Если счётчик < 0 то вызываем событие end и отдаём результат
if(!done) emit('end', this.text);
@intech
intech / gist:5879743
Last active December 19, 2015 01:59
// we need the fs module for moving the uploaded files
var fs = require('fs'),
EventEmitter = require('events').EventEmitter;
var uploadQueue = new EventEmitter();
uploadQueue.on('upload', function(tmp_path, target_path) {
// move the file from the temporary location to the intended location
fs.rename(tmp_path, target_path, function(err) {
if (err) throw err;
// delete the temporary file, so that the explicitly set temporary upload dir does not get filled with unwanted files
@intech
intech / app.js
Last active December 21, 2015 05:39
Example
var express = require('express'),
// стандартные либы
http = require('http'),
path = require('path'),
// подключаем mongodb
MongoClient = require('mongodb').MongoClient,
// ObjectID
ObjectID = require('mongodb').ObjectID;
// Подключаемся к БД
@intech
intech / rc4.js
Created October 5, 2013 09:20
rc4
/**
* Encrypt given plain text using the key with RC4 algorithm.
* All parameters and return value are in binary format.
*
* @param string key - secret key for encryption
* @param string pt - plain text to be encrypted
* @return string
*/
exports = module.exports = function rc4(key, pt) {
s = new Array();
@intech
intech / test.js
Created October 5, 2013 09:25
AES256
// RC4 PRIVATE KEY
var key = '123456789';
var file = 'test123456';
// Encrypt
var crypto = require('crypto');
var cipher = crypto.createCipher('aes-256-cbc', key);
var encfile = cipher.update(file, 'utf8', 'hex');
encfile += cipher.final('hex');
@intech
intech / app.js
Created May 15, 2014 22:24
Урок про modules и async.queue
#!/usr/bin/node
function cb(data) {
console.log('[>] Выполнена задача', data);
}
function empty() {
console.log('[!] Очередь пуста (выполняется последнее задание)');
}
function drain() {
console.log('[!] Все задания выполнены (последнее задание выполнено)');
@intech
intech / stats.get.json
Last active August 29, 2015 14:24
stats.get.json
{
"success": true,
"code": 200,
"stats": [{
"day": "2015-05-22",
"views": 1,
"visitors": 1,
"reach": 1,
"reach_subscribers": 0,
"subscribed": null,
@intech
intech / Handler.php
Last active April 27, 2016 15:04
Laravel to elasticsearch error handler by udp json
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
@intech
intech / .htaccess
Last active November 15, 2016 08:19 — forked from anonymous/.htaccess
Закрытие директории загрузки от исполнения
# Запрещаем листинг директории
Options -Indexes
# Здесь мы запрещаем доступ из веба к файлам с расширениями
<FilesMatch "\.(php|cgi|pl|php|php3|php4|php5|php6|php7|phps|phtml|shtml|py|phtml|pl|asp|aspx|cgi|dll|exe|ico|shtm|shtml|fcg|fcgi|fpl|asmx|pht|py|psp)$">
Order allow,deny
Deny from all
</FilesMatch>
# Ниже мы говорим, что данные расширения отдавать как текст, чтобы не выполнять как исполняемые файлы
@intech
intech / startkit.sh
Created October 8, 2018 08:12
swap+kernel tuning
#!/bin/bash
apt update && apt upgrade -y && apt install -y mc htop curl git
# swap
fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab