Skip to content

Instantly share code, notes, and snippets.

@AleksMeshkov
AleksMeshkov / simple-nodejs-iv-encrypt-decrypt.js
Created March 8, 2019 00:06 — forked from yoavniran/simple-nodejs-iv-encrypt-decrypt.js
nodejs crypto - simple encrypt & decrypt using IV (Initialization Vector)
"use strict";
var crypto = require("crypto");
var EncryptionHelper = (function () {
function getKeyAndIV(key, callback) {
crypto.pseudoRandomBytes(16, function (err, ivBuffer) {
var keyBuffer = (key instanceof Buffer) ? key : new Buffer(key) ;
@AleksMeshkov
AleksMeshkov / about.md
Created March 7, 2019 13:19 — forked from caike/about.md
Node.js streams 1 vs. 2

NodeJS Streams

  • Current implementation is known as streams2.
  • Introduced in node v0.10.
  • "suck" streams instead of "spew" streams.
  • Instead of data events spewing, call read() to pull data from source.
  • When there isn't any data to consume, then read() will return undefined.
  • Adding a data event listener will switch the Readable stream into "old mode", where data is emitted as soon as it is available rather than waiting for you to call read() to consume it. This requires you to handle backpressure problems manually.
  • The pipe method helps write less code and handles back-pressure.
  • If you add an end listener and don't ever read() or pipe(), it'll never emit end.
// requirements
var PHPUnserialize = require('php-unserialize'); // npm install php-unserialize
var MCrypt = require('mcrypt').MCrypt; // npm install mcrypt
// helper function
function ord( string ) { // Return ASCII value of character
//
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
«Джефф Дин не пользуется ни Emacs’ом, ни Vi. Он набирает код непосредственно в zcat, потому что так быстрее».
«Когда Ричард Столлман узнал, что автобиография Дина выйдет эксклюзивно на платформе Amazon, он купил Kindle».
«Недовольный константным временем, Джефф Дин создал первый в мире алгоритм O(1/n)».
«Однажды в 2002 году, когда поисковый бэкенд отключился, Джефф Дин два часа вручную отвечал на вопросы пользователей. В этот период качество поисковой выдачи существенно возросло».
«Джеффу Дину пришлось изобрести асинхронные API однажды, когда после его оптимизации функция вернула значение прежде, чем её вызвали».
<?php
function dailyDate($timestamp){
if(is_string($timestamp)) $timestamp = strtotime($timestamp);
$minuts_map = array("минут", "минута", "минуты", "минуты", "минуты",
"минут", "минут", "минут", "минут", "минут");
$hours_map = array("", "1 час", "2 часа", "3 часа", "4 часа", "5 часов", "6 часов",
"7 часов", "8 часов", "9 часов", "10 часов", "11 часов",
"12 часов", "13 часов", "14 часов", "15 часов", "16 часов",
"17 часов", "18 часов", "19 часов", "20 часов", "21 час",
http = require 'http'
nodemailer = require 'nodemailer'
transport = nodemailer.createTransport 'SMTP',
host: 'smtp.....' # hostname
port: 25 # port for secure SMTP
auth:
user: 'user'
pass: 'password'
console.log 'SMTP Configured'
@AleksMeshkov
AleksMeshkov / buildGrid.js
Created October 22, 2012 11:05
Fun with algorythms
/**
* Author: Meshkov Aleksey (tomeshkov@gmail.com)
*/
// Compressed code (with http://jscompress.com/):
function buildGrid(a,b,c){a=a||"1";b=b||"0";c=Math.abs(c)||8;var d,e,f="";for(var g=0;g<c;g++){d=g%2?a:b;f+=d+" ";for(var h=0;h<c-1;h++){e=g%2?b:a;f+=e+" "}console.log(f);f=""}}
// Uncompressed code:
{
"name": "bbg",
"version": "0.0.0",
"dependencies": {
"angular-animate": "~1.3.4",
"angular-cookies": "~1.3.4",
"angular-touch": "~1.3.4",
"angular-sanitize": "~1.3.4",
"jquery": "~2.1.1",
"angular-ui-router": "~0.2.13",
{
"generator-gulp-angular": {
"version": "0.11.0",
"props": {
"angularVersion": "~1.3.4",
"angularModules": [
{
"key": "animate",
"module": "ngAnimate"
},
#!/bin/sh
# Just copy and paste the lines below (all at once, it won't work line by line!)
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY!
function abort {
echo "$1"
exit 1
}
set -e