Skip to content

Instantly share code, notes, and snippets.

View tomi's full-sized avatar

Tomi Turtiainen tomi

View GitHub Profile
import { from } from "fromfrom";
var sequence = from([1, 2, 3, 4])
.map(x => {
console.log(x);
return x;
})
.map(x => x * 2)
.take(1)
.toArray(); // Needed to force the evaluation
import { from } from "fromfrom";
var sequence = from([1, 2, 3, 4])
.map(x => {
console.log(x);
return x;
})
.filter(x => x > 2);
// Nothing is printed the console yet
var someArray = [1, 2];
var iterator = someArray[Symbol.iterator]();
iterator.next(); // { value: 1, done: false }
iterator.next(); // { value: 2, done: false }
iterator.next(); // { value: undefined, done: true }
interface Iterable<T> {
[Symbol.iterator](): Iterator<T>;
}
interface Iterator<T> {
next(value?: any): IteratorResult<T>;
return?(value?: any): IteratorResult<T>;
throw?(e?: any): IteratorResult<T>;
}
import { from } from "fromfrom";
const users = [
{ id: 1, name: "John", age: 31, score: 2244, active: true },
{ id: 2, name: "Jane", age: 32, score: 2492, active: false },
{ id: 3, name: "Luke", age: 33, score: 2500, active: false },
{ id: 1000, name: "Mary", age: 34, score: 2290, active: true },
];
@tomi
tomi / README.md
Last active March 14, 2024 03:28
Saving and reading private key to env variables using base64

Encoding the private key as base64

  • Copy the private key to clipboard
  • Run command pbpaste | base64 | pbcopy
  • The private key is now base64 encoded in the clipboard. Paste it to env variable e.g. to heroku or to .env file

Decoding the private key from base64 in node.js

const private_key = new Buffer(process.env.PRIVATE_KEY, 'base64').toString('ascii');
@tomi
tomi / vscode-debug-node-in-vm.md
Last active January 13, 2020 07:50
How to debug a node process running in VM with VS Code
  1. Launch the node process in the VM with --debug-brk flag. This will break the execution of the node process in the start. node --debug-brk <app.js> <args>. Node.js versions >= 6.3 support new inspector protocol: node --inspect <app.js> <args>

  2. Create a launch config in VS Code with a mapping from the VM file system to the local file system

{
  "name": "Attach node",
  "type": "node",
  "request": "attach",
 "address": "localhost",
on *:KICK:#:{
if (($knick == $me) && ($nick != $me)) {
/write revenge.txt $chan � $nick � $asctime(HH:nn dd/mm/yyyy)
}
}
on *:OP:#:{
if ($opnick == $me) /tarkistappa
}