Skip to content

Instantly share code, notes, and snippets.

@VRMink
VRMink / agent_with_custom_tool.ipynb
Created April 19, 2023 07:08 — forked from virattt/agent_with_custom_tool.ipynb
agent_with_custom_tool.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@VRMink
VRMink / gist:9810690
Created March 27, 2014 15:51
Generate GET query from key value pairs with underscore
function urlFromParams(user){
return _.chain(user)
.map(
function(value, key){ return encodeURI(key)+'='+encodeURI(value);}
)
.reduce(
function(memo, value){return memo+'&'+value;}
).value();
}
@VRMink
VRMink / gist:9547403
Created March 14, 2014 13:11
A simple reverse proxy for developing
var http = require('http'),
httpProxy = require('http-proxy');
//
// A simple round-robin load balancing strategy.
//
// First, list the servers you want to use in your rotation.
//
var forwarding = {
"s.paddle.to" : {
target: "http://localhost:8001"
@VRMink
VRMink / gist:7561268
Created November 20, 2013 10:53
Search your whole git branch, for one phrase
git filter-branch --tree-filter "grep -R PHRASE * | cat $1" HEAD

Title: F-mail Date: 2013-07-10 20:31

I hope that after reading this you will help me help our people ensure their right to private communication. Please share my opinions and ideas with as many people as you like.

Now the NSA and PRISM revelations has given techies a unique oppertunity to raise the issue and suggest a better e-mail system.

Let us get a bit more technical. E-mail is broken because no matter how you encrypt it you will always reveal meta data that is enough to tell who you talk to, when, about what subject, and how often - and if you encrypt it you send a very clear signal to whoever is watching. We need to solve those problems.

E-mail reveals:

@VRMink
VRMink / gist:5526169
Created May 6, 2013 16:19
Idea for a fallback library
fallback.json
-------
{
email: 'devops@example.com',
disk: '/var/log/failure/marshalled'
}
Node code
-------
var fallback = require('fallback');

How to deduce the Certificate Authority file (cacert.pem / cert.pem) used by OpenSSL

On most unix system there is an application called dtrace which will tell you all the system calls made in real time, and it can filter on filesystem operations. So to cut a long story short, here's a simple guide to figuring out the CA file used by your openssl library.

  1. Start dtrace on filesystem calls and save the output into a file
  • sudo dtrace -n 'syscall::open*:entry { printf("%s %s", execname, copyinstr(arg0))}' > dtrace.out
  1. Run the application which searches for does the CA lookup on the filesystem, this can be done in another terminal session.
  2. Grep the output file (dtrace.out) for the application name, and read the path
  • cat dtrace.out | grep ruby
@VRMink
VRMink / gist:5494594
Last active December 16, 2015 20:39
How to extract time from MongoDB _id's and how to create custom _id's with future dates and times

Extracting Date and Time from the MongoDb _id field

Until recently, many of the MongoDB models I worked with contained an extra field "created", which did nothing but state when the document was created. That is fine if you need millisecond precision, but if all you are after is wall clock precision, then you can extract the date from the autogenerated _id field on the document.

var ObjectId = require('mongodb').ObjectID
ObjectId.createFromTime(Date.now()/1000 ).getTimestamp()

This works because the first 4 bytes in the ID are the date. The method getTimestamp converts these 4 bytes to a Date with precision down to a second.

@VRMink
VRMink / gist:5169211
Last active January 6, 2020 20:31
How to setup a private node.js web server with SSL authorization

Secure private web server with NodeJS

This article will explain how to set up a secure web server with NodeJS which only accepts connection from users with SSL certificates that you have signed. This is an efficient way to ensure that no other people are able to access the web server, without building a login system which will be significantly weaker.

I will not explain how to create a certificate authority (CA), create certificates or sign them. If you need to read up on this, have a look at this excelent article on how to do it with OpenSSL (Mac and Linux): https://help.ubuntu.com/community/OpenSSL#Practical_OpenSSL_Usage It is also possible to do this on a Mac with the keychain application, and I assume it is possible on a Windows machine aswell.

This architecture will allow you to have one web server communicating with an array of trusted clients, the web server itself can be on the public internet, that will not decrease the level of security, but it will only ser