Skip to content

Instantly share code, notes, and snippets.

@davidrapin
davidrapin / neo4js.js
Created November 26, 2015 16:25
Start/stop/status on multiple Neo4j instances
/**
* Start, stop or get the status of all Neo4j installations in current folder.
*
* Usage:
* >node neo4js status
* >node neo4js start
* >node neo4js stop
* Author: David Rapin
* Date: 2015-11-26.
* licence: MIT

In order to keep this easy to navigate, it is asked that you squash your commits down to a few, or one, discreet changesets before submitting a pull request. Fixing a bug will usually only need one commit, while a larger feature might contain a couple of separate improvements that is easier to track through different commits.

Once you have rebased your work on top of the latest state of the upstream master, you may have several commits related to the issue you were working on. Once everything is done, squash them into a single commit with a descriptive message, like "Issue #100: Retweet bugfix."

To squash four commits into one, do the following:

$ git rebase -i HEAD~4

In the text editor that comes up, replace the words "pick" with "squash" next to the commits you want to squash into the commit before it. Save and close the editor, and git will combine the "squash"'ed commits with the one before it. Git will then give you the opportunity to change your commit message to something like, "Issue #100: Fixed r

@davidrapin
davidrapin / main.js
Created April 4, 2016 16:08
NodeJS module security
// this is a work-in-progress (currently broken), don't use it as-is.
function patchRequire(verbose) {
var Module = require('module');
var originalRequire = Module.prototype.require;
var SENSITIVE_MODULES = ['fs', 'child_process', 'cluster', 'vm'];
var stack = [];
/**
* @param {string} moduleId Package id
@davidrapin
davidrapin / howto.md
Created November 21, 2016 16:48
store TypeScript type metadata for runtime check

sauce

You should be able to use the TypeChecker API from the compiler to get to the type information you need. there is no serialization logic readily available, but should be possible to add one.

Here is the TypeChecker API: https://github.com/Microsoft/TypeScript/blob/085f0df4556801c14a4333d6c1d0bab1375586e4/lib/typescript.d.ts#L1027-L1057

Documentation on using the compiler API: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API

Here is the part of the emitter that emitts this infromation today using the Checker: https://github.com/Microsoft/TypeScript/blob/085f0df4556801c14a4333d6c1d0bab1375586e4/src/compiler/emitter.ts#L5065-L5104

@davidrapin
davidrapin / index.html
Last active October 12, 2017 17:00
Simple D3 histogram
<!DOCTYPE html>
<meta charset="utf-8">
<style>
svg {
border: 1px solid red;
}
</style>
@davidrapin
davidrapin / hash-modulo.js
Last active February 6, 2018 18:37
Hash modulo
// from https://www.npmjs.com/package/sha1
var sha1 = require("sha1")
// compute (sha1) hash modulo
function hash_modulo(str, modulo) {
// ignore case of input
str = str.toUpperCase();
// compute sha1 of input
let h = sha1(str);
// use only the 8 last bytes (4 last hex chars) of the sha1
@davidrapin
davidrapin / start-unifi-app.sh
Last active February 24, 2021 22:40
Start UniFi app (OSX)
# go to correct home folder (itgerwise tomcat will fail)
cd /Applications/UniFi.app/Contents/Resources/
# start unify app with correct java-home (java8 needed)
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/ java -jar /Applications/UniFi.app/Contents/Resources/lib/ace.jar ui &
# open your browseron the local server
open https://localhost:8443
@davidrapin
davidrapin / !Clean_Silver_Sparrow.md
Last active February 24, 2021 22:39
Detect & Remove Silver Sparrow

What is Silver Sparrow?

https://redcanary.com/blog/clipping-silver-sparrows-wings/

Running the cleaner

Past this in a Terminal window:

curl -s https://gist.githubusercontent.com/davidrapin/f74010691e9a08ab9ca225949e622bba/raw/03d1927c01178bd44416da70f464a2d8a34d8b52/ssp-clean.sh | bash -s --
@davidrapin
davidrapin / !random-dates.cypher
Last active March 17, 2026 19:41
Create random dates (Neo4j Cypher)
// amount: number of random dates to create
// startYear: year range start
// startYear: year range end
WITH 1000 as amount, 2017 as startYear, 2021 as endYear
WITH range(1, amount) as xx, startYear, (endYear - startYear) as yearRange
UNWIND xx as x
WITH date({
year:toInteger(1+startYear+floor(rand()*yearRange)),
month:toInteger(1+floor(rand()*12)),
@davidrapin
davidrapin / !generate_edge_types.cypher
Created March 5, 2021 10:15
Generate edge types (Neo4j Cypher)
// edgeCount: the number of edges with a unique edge-type to generate
// sourceNodeId: ID of the node to be used as source for all generated edges
// targetNodeId: ID of the node to be used as target for all generated edges
// prefix: the edge-type prefix to use for generated edge-types
WITH 100 as edgeCount, 1 as sourceNodeId, 2 as targetNodeId, "edge_type_prefix_" as prefix
MATCH (a), (b) WHERE id(a) = sourceNodeId and id(b) = targetNodeId
WITH range(1, edgeCount) as xx, a, b
UNWIND xx AS x
CALL apoc.create.relationship(a, prefix + toString(x), {property: x}, b) YIELD rel