Skip to content

Instantly share code, notes, and snippets.

View tjunghans's full-sized avatar
💭
Open for business

Thomas Junghans tjunghans

💭
Open for business
View GitHub Profile
# Unix find documentation: https://kb.iu.edu/d/admm
# Remove all node_modules that were modified 60 days or earlier (to free up disc space)
find ./* -maxdepth 1 -path '*node_modules*' -type d -mtime +60 -exec rm -rf {} \;
# Show all directories containing node_modules that were modified 60 days or earlier
find ./* -maxdepth 1 -path '*node_modules*' -type d -mtime +60 -print
# Run this script where all the checked out projects are.
find . -maxdepth 2 -type d -ctime +60 -name node_modules | grep -vE "(node-deploy|node-release|stash-client|kibana-dashboards|package-manager)" | xargs rm -rf
@tjunghans
tjunghans / get-contents.js
Last active September 19, 2016 18:32
Reading directory contents using node
const fs = require("fs");
const path = require("path");
const PATH = "."
function listDirs(files) {
files.forEach(file => {
fs.stat(path.join(PATH, file), (err, stats) => {
if (stats.isDirectory()) {
console.log(file);
@tjunghans
tjunghans / search.sh
Created October 5, 2016 14:57
Find string in a directory recursively
find . -type f -print0 | xargs -0 grep -l "needle"
@tjunghans
tjunghans / tests.sh
Created October 20, 2016 07:43
showing all test suites and cases in a mocha based test file
cat test-file.js | grep "\(it(\|describe(\)"

Single Responsibility

Applies to everything: components, services, directives, etc.

Rule of One

  • One thing per file
  • Max 400 lines of code per file

Small Functions

@tjunghans
tjunghans / currencies.js
Created December 13, 2016 20:34
G10 currencies (includes G5)
// the first five are the G5 currencies. The whole lot are the G10
const currencies = ["EUR", "GBP", "YEN", "USD", "CHF", "AUD", "CAD", "NZD", "NOK", "SEK"];
@tjunghans
tjunghans / grid.css
Created January 12, 2017 14:57
Grid CSS
// Based on material css
.container {
margin: 0 auto;
.row {
margin-left: -4px;
margin-right: -4px;
}
}
.row {
@tjunghans
tjunghans / Google-Chrome-User-Agent.sh
Last active January 17, 2017 10:13
Start Google Chrome with different useragent
# Run Chrome as IE11
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; Ypkch32; rv:11.0) like Gecko"
@tjunghans
tjunghans / debug-log.js
Created January 27, 2017 10:32
Debug Logging
function log(value, label = "-") {
console.log(" ");
console.log(" ");
console.log(label, JSON.stringify(value, null, " "));
}
@tjunghans
tjunghans / error_handling_promise.md
Last active May 9, 2017 12:58
Promise Error Handling

Promise Error Handling

  • Errors can be handled in a synchronouse fashion
  • You can throw an exception in a Promise
  • You can reject a promise with an exception
  • You can catch an exception with Promise catch

Throwing and Rejecting Errors

Example 1: Throwing an Error