Skip to content

Instantly share code, notes, and snippets.

@GuyMograbi
GuyMograbi / .guy_bash_prompt
Created February 3, 2019 16:30
my bash prompt
# get current branch in git repo
function parse_git_branch() {
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ ! "${BRANCH}" == "" ]
then
STAT=`parse_git_dirty`
echo "[${BRANCH}${STAT}]"
else
echo ""
fi
@GuyMograbi
GuyMograbi / index.js
Created October 7, 2018 19:04
trigger bitbucket pipeline from lambda. overcome 5 scheduled builds limit.
const https = require('https');
function doCall (opts = {}, callback) {
console.log(`doCall with opts ${JSON.stringify(opts, {}, 2)}`);
const data = {
'target': {
'selector': {
'type': 'branches',
'pattern': opts.pipeline_name
@GuyMograbi
GuyMograbi / origin-middleware.js
Created July 21, 2017 16:03
absoluteUrl middleware in express
/**
*
* @description
* adds an <code>absoluteUrl</code> function on request
*
* <pre>
* var absoluteUrl = req.absoluteUrl('/myRelativeUrl'); //==> http://my.domain/myRelativeUrl
* </pre>
*
* and variable <code>origin</code> on request which will be equals to <code>http://my.domain</code>
@GuyMograbi
GuyMograbi / index.js
Last active June 23, 2017 22:10
original code for improve-stack-post
function getName () {
return new Promise((resolve)=>{
resolve({status:500});
}); // emulate http call
}
function getFullName (info) {
return new Promise((resolve) => {
resolve(info.firstName + ' ' + info.lastName)
})
@GuyMograbi
GuyMograbi / validation.js
Last active June 23, 2017 22:08
improve javascript stacktrace
function getName () {
return new Promise((resolve)=>{
resolve({status:500});
}).then((response) => { // validate output
if (response.status === 500){
throw new Error('request to get name has failed');
}else{
return response;
}
}); // emulate http call
@GuyMograbi
GuyMograbi / index.js
Created June 23, 2017 22:08
upper print for - improve-stack-post
analyzeName().then((result) => {
console.log(result);
}).catch((e)=>{
console.log('failed to analyze name',e);
});
@GuyMograbi
GuyMograbi / output-3.sh
Created June 23, 2017 22:08
output 3 - for improve-stack-post
Error: failed analyzing name. result status {“name”:{“firstName”:”foo”,”lastName”:”bar”}}
at getName.then.then.then.then.catch (/Users/guymograbi/dev_env/projects_GIT/posts/improve_stacktrace/index.js:55:24)
...
Caused By:
Error: fullName is missing
at countLetters (/Users/guymograbi/dev_env/projects_GIT/posts/improve_stacktrace/index.js:32:15)
...
@GuyMograbi
GuyMograbi / output-2.sh
Created June 23, 2017 22:07
output 2 - for improve-stack-post
Error: failed analyzing name. result status {}
at getName.then.then.then.then.catch (/Users/guymograbi/dev_env/projects_GIT/posts/improve_stacktrace/index.js:55:24)
...
Caused By:
Error: request to get name has failed
at Promise.then (/Users/guymograbi/dev_env/projects_GIT/posts/improve_stacktrace/index.js:6:19)
...
@GuyMograbi
GuyMograbi / output.sh
Created June 23, 2017 22:06
output - 1 for improve-stack-post
(node:12977) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'firstName' of undefined
(node:12977) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:12977) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 28): TypeError: Cannot read property 'split' of undefined
(node:12977) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 29): TypeError: Cannot read property 'split' of undefined
...
@GuyMograbi
GuyMograbi / index.js
Created June 23, 2017 22:03
concatenate stack
function analyzeName () {
...
}).catch((e)=>{
const reason = new Error(`failed analyzing name. result status ${JSON.stringify(result)}`);
reason.stack += `\nCaused By:\n` + e.stack;
return reason;
})
}