Skip to content

Instantly share code, notes, and snippets.

View smellymonk's full-sized avatar
📜
ora et labora

Thomas Klemz smellymonk

📜
ora et labora
View GitHub Profile
@smellymonk
smellymonk / flatten.js
Created October 15, 2018 17:43
Array deep flatten in JS
function flatten(arr) {
return arr.reduce((flat, item) =>
flat.concat(Array.isArray(item) ? flatten(item) : item), [])
}
// usage:
flatten([[1,2,[3]], 4]) // [1,2,3,4]
@smellymonk
smellymonk / utils.sh
Last active September 5, 2018 21:48
Bash utilities for working with NodeJS projects
# Some useful random Bash utils, mostly for working with NodeJS projects. I use `dep` and `findjs` the most. :)
# You can just stuff these in your .bashrc or .zshrc
alias bork='rm -rf ./node_modules && yarn install'
# an actual bork:
# alias bork='find ./node_modules -type d -depth 1 | sort -R | sed 1q | rm -rf'
# simple libre:
# alias libre='find . -type d -name "node_modules" -prune -o -name "package-lock.json" -exec rm {} \;'
@smellymonk
smellymonk / asyncAll.js
Last active October 5, 2018 04:52
asyncAll example
/*
* A simple asyncAll example.
*
* Ignores any error handling and only returns the results to the done callback.
* Each task is expected to take a callback for its first parameter.
*/
// Example call:
asyncAll([doSomething, doSomethingElse], function (results) {
console.log('all done', results);
function merge (repo, remotePath) {
var remoteName = 'superman';
var remoteBranch = 'master'
var remoteHeadRef = 'refs/remotes/' + remoteName + '/HEAD';
var remoteMasterRef = 'refs/remotes/' + remoteName + '/master';
var ourBranchName = 'master';
var newBranchName = 'wonderwoman';
NodeGit.Remote.create(repo, remoteName, remotePath);
function createBranch(repo, newBranchName, remoteName, remoteBranch) {
var remoteRefBase = 'refs/remotes/' + remoteName;
var remoteRefName = remoteRefBase + '/' + remoteBranch;
var remoteRefHead = remoteRefBase + '/' + 'HEAD';
return NodeGit.Reference.symbolicCreate(repo, remoteRefHead, remoteRefName, 1, 'Setting HEAD')
.then(function () {
return repo.getReference(remoteRefName);
})
.then(function (remoteRef) {
{
"_links": {
"self": "/contacts"
},
"_embedded": {
"contact": [{
"_links": {
"self": { "href": "/contacts/1" }
},
"name": "Bob Marley",
{
"_links": {
"self": { "href": "/customers/1234" },
"collection": { "href": "/customers" }
},
"name": "Bob Jones",
"street": "123 California Ave",
"city": "Sacramento",
"state": "CA",
"zip": "12345",
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Producer Commission",
"description": "Producer commission statements",
"type": "object",
"properties": {
"startDate": {
"title": "Start Date",
"type": "string",
"format": "date"
DECLARE Id INT, @Title VARCHAR(50)
DECLARE Iterator CURSOR FORWARD_ONLY FOR
SELECT Id, Title FROM dbo.SourceTable
OPEN Iterator
WHILE 1=1 BEGIN
FETCH NEXT FROM @InputTable INTO @Id, @Title
IF @@FETCH_STATUS < 0 BREAK
PRINT 'Do something with ' + @Title
END
CLOSE Iterator
@smellymonk
smellymonk / 001-hal-reports-response
Created February 8, 2015 06:57
embedded vs links
{
"_links": {
"self": { "href" : "https://cloud.paulmarsoftware.com/api/nobl/reports" },
"group": [
{ "title": "Accounting", "href" : "https://cloud.paulmarsoftware.com/api/nobl/reports/accounting" },
{ "title": "Account Details", "href" : "https://cloud.paulmarsoftware.com/api/nobl/reports/account-details" },
...
...
]
}