Skip to content

Instantly share code, notes, and snippets.

Guy Mograbi GuyMograbi

Block or report user

Report or block GuyMograbi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View .guy_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 Oct 7, 2018
trigger bitbucket pipeline from lambda. overcome 5 scheduled builds limit.
View index.js
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 Jul 21, 2017
absoluteUrl middleware in express
View origin-middleware.js
/**
*
* @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
Created Jun 23, 2017
upper print for - improve-stack-post
View index.js
analyzeName().then((result) => {
console.log(result);
}).catch((e)=>{
console.log('failed to analyze name',e);
});
@GuyMograbi
GuyMograbi / output-3.sh
Created Jun 23, 2017
output 3 - for improve-stack-post
View output-3.sh
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 Jun 23, 2017
output 2 - for improve-stack-post
View output-2.sh
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 Jun 23, 2017
output - 1 for improve-stack-post
View output.sh
(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
Last active Jun 23, 2017
original code for improve-stack-post
View index.js
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 / index.js
Created Jun 23, 2017
concatenate stack
View index.js
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;
})
}
@GuyMograbi
GuyMograbi / 0_reuse_code.js
Created Jun 23, 2017
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
You can’t perform that action at this time.