Skip to content

Instantly share code, notes, and snippets.

@AleksMeshkov
AleksMeshkov / simple-nodejs-iv-encrypt-decrypt.js
Created Mar 8, 2019 — forked from yoavniran/simple-nodejs-iv-encrypt-decrypt.js
nodejs crypto - simple encrypt & decrypt using IV (Initialization Vector)
View simple-nodejs-iv-encrypt-decrypt.js
"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 Mar 7, 2019 — forked from caike/about.md
Node.js streams 1 vs. 2
View about.md

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.
View bower.json
{
"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",
View .yo-rc.json
{
"generator-gulp-angular": {
"version": "0.11.0",
"props": {
"angularVersion": "~1.3.4",
"angularModules": [
{
"key": "animate",
"module": "ngAnimate"
},
View uninstall_homebrew.sh
#!/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
View controllers.js
$scope.specialist.photoUrl = false;
//Workaround for issue described here: https://issues.apache.org/jira/browse/CB-7131
var imgLoadErr = function () {
$scope.specialist.photoUrl = false;
};
var img = new Image();
img.onerror = imgLoadErr;
img.onabort = imgLoadErr;
img.onload = function () {
View gist:d5a938f87b292ae66da5
<script>
/*jslint unparam: true */
/*global window, $ */
$(function () {
'use strict';
// Change this to the location of your server-side upload handler:
function removeErrorLabels() {
$('label.error-message').remove();
}
View How to decrypt Laravel's sessionID in NodeJS
// 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)
View gist:9974304
<?php
/*
* Locale checker
*/
\App::setLocale('ru');
$languages = array('ru', 'en', 'ua', 'by', 'kz', 'md');
$locale = Request::segment(1);
View gist:9738879
<?php
return array (
'host' => '127.0.0.1',
'port' => 9312,
'indexes' => array (
'discash_offers' => array ( 'table' => 'offers', 'column' => 'id' ),
'discash_products' => array ( 'table' => 'products', 'column' => 'id' ),
)
);