Skip to content

Instantly share code, notes, and snippets.

View asanchezr's full-sized avatar

Alejandro Sanchez asanchezr

  • Victoria BC, Canada
View GitHub Profile
@asanchezr
asanchezr / .bash_profile
Last active November 9, 2018 04:44
Git branch in bash prompt
# Git branch in prompt.
parse_git_branch() {
git branch --no-color 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
parse_git_dirty() {
[[ -z $(git status --porcelain 2>/dev/null) ]] || echo "*"
}
git_prompt() {
# First, get the branch name...
local branch="$(parse_git_branch)"
@asanchezr
asanchezr / throttle.jsx
Created September 29, 2018 18:03
Throttle function in JavaScript
/*
* This is helpful when you want a function to execute after an event happens but if that event happens very rapidly
* you can delay the execution and improve the performance of your application by executing the function only
* when the events stop happening.
*
* For e.g.
* Imagine you have to implement a search box which calls the API whenever the user types something into it.
*/
// throttle function
@asanchezr
asanchezr / bigONotation.js
Created September 23, 2018 21:59
Big O Notation Exercises
// 1. Even or odd
function isEven(value){
if (value % 2 == 0){
return true;
}
else
return false;
}
@asanchezr
asanchezr / Starter script for OpenShift provisioning (needs adapting).md
Last active September 11, 2018 18:58
Starter script for OpenShift provisioning (needs adapting)

Automated Deploy on OpenShift

You can use the scripts/provision.sh script provided to deploy the entire demo:

./provision.sh --help
./provision.sh deploy
./provision.sh delete 
@asanchezr
asanchezr / Recipe (JavaScript) - Create URL-friendly version of a DB field.md
Last active August 27, 2018 23:14
Recipe (JavaScript) - Create URL-friendly version of a DB field, eg: "a-great-article"

Summary (TL;DR)

  • Import NPM dependency slugify
  • Use it, e.g. slugify(someString).toLowerCase()

Details:

Create a new file named ./models.js and copy the following code inside of it.

@asanchezr
asanchezr / GitHub - Force your forked repo to be the same as upstream.md
Last active September 17, 2018 19:44 — forked from glennblock/fork forced sync
Force your forked repo to be the same as upstream
git fetch upstream
git reset --hard upstream/master
git push origin master -f
@asanchezr
asanchezr / colors.sh
Created August 20, 2018 17:42 — forked from mavieth/colors.sh
Bash script color output
#!/bin/bash
DARKGRAY='\033[1;30m'
RED='\033[0;31m'
LIGHTRED='\033[1;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
LIGHTPURPLE='\033[1;35m'
@asanchezr
asanchezr / GitHub - Import upstream branch into fork.md
Created August 16, 2018 06:56
GitHub - Import upstream branch into fork

Problem

I have a fork (origin) from a project (upstream) on github. Now the upstream project has added a new branch, I want to import into my fork. How do I do that?

I tried checking out the remote and creating a branch on top of that, but that configures the branch the way that git push is trying to push to the upstream:

git checkout upstream/branch
git checkout -b branch
@asanchezr
asanchezr / bash.cheat
Created July 24, 2018 23:28 — forked from afair/bash.cheat
Bash Scripting Quick Reference
==========================================
BASH SCRIPTING ==========================================
========================================== TEST COMMAND
==========================================
Invoke: bash [options] file
Shebang: #!/usr/bin/env bash Test: test expression
In script: [ expression ]
========================================== Alternate: [[ espression ]]
LOOP Does not split string words
========================================== Does not expand pathglobs*
@asanchezr
asanchezr / 01-directory-structure.md
Created July 19, 2018 22:27 — forked from tracker1/01-directory-structure.md
Anatomy of a JavaScript/Node project.

Directory structure for JavaScript/Node Projects

While the following structure is not an absolute requirement or enforced by the tools, it is a recommendation based on what the JavaScript and in particular Node community at large have been following by convention.

Beyond a suggested structure, no tooling recommendations, or sub-module structure is outlined here.

Directories

  • lib/ is intended for code that can run as-is
  • src/ is intended for code that needs to be manipulated before it can be used