Skip to content

Instantly share code, notes, and snippets.

View diversemix's full-sized avatar
🎯
Focusing

Peter Hooper diversemix

🎯
Focusing
View GitHub Profile
@diversemix
diversemix / check-repos.sh
Created May 9, 2022 09:36
Audit npm in repositories below cwd
#!/bin/bash
file=$PWD/audit.md
[ -f $file ] && rm $file
repos=$(find . -name package.json | grep -v node_modules)
echo "# Repository Audit $(date)" >> $file
for repo in $repos
do
@diversemix
diversemix / create-node-project.sh
Last active February 21, 2022 14:08
Create new node project
#!/bin/bash
#
# Takes one argument - the name of the package
#
mkdir $1
cd $1
npm init -y
echo 'console.log("hello");'>> index.js
cat package.json |jq --argjson scripts '{"start": "node ./index.js"}' '.scripts += $scripts' > new_package.json
@diversemix
diversemix / a-rabbitmq-demo.sh
Last active February 4, 2022 17:54
RabbitMQ node demo
#!/bin/bash
npm install
start() {
docker run -d --rm -p 5672:5672 rabbitmq
echo Waiting 5 secs....
sleep 5
}
class DataCache {
constructor(fetchFunction, minutesToLive = 10) {
this.millisecondsToLive = minutesToLive * 60 * 1000;
this.fetchFunction = fetchFunction;
this.cache = null;
this.getData = this.getData.bind(this);
this.resetCache = this.resetCache.bind(this);
this.isCacheExpired = this.isCacheExpired.bind(this);
this.fetchDate = new Date(0);
}
@diversemix
diversemix / rotate.py
Created November 2, 2020 11:26
Python to rotate a string
# Given a number write a function that finds all rotations of its digits.
# For example for 197 the output would be 197, 971, and 719.
# Rotation is first diget to the moved to the end
# Last diget moved to the start
num = 1973
def rotate(num_str):
return num_str[-1] + num_str[0:-1]
@diversemix
diversemix / vscode_shortcuts.md
Created October 6, 2020 17:12 — forked from bradtraversy/vscode_shortcuts.md
Helpful shortcuts for VSCode

VSCode Shortcuts

List of helpful shortcuts for faster coding

If you have any other helpful shortcuts, feel free to add in the comments of this gist :)

Official List of all commands

@diversemix
diversemix / bq-partitioning.md
Last active August 21, 2020 12:53
BigQuery - partitioning example

BigQuery Partitioning

This is a little investigation into how to create Column Partitions in BigQuery.

Create Table

CREATE TABLE test.Events(
  id int64,
  type string,
 info string,
@diversemix
diversemix / bq-partitioning.md
Created August 21, 2020 12:37
BigQuery - partitioning example

BigQuery Partitioning

Create Table

CREATE TABLE test.Events(
  id int64,
  type string,
  info string,
  time date
) PARTITION BY time
@diversemix
diversemix / clean_code.md
Created June 16, 2020 13:50 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@diversemix
diversemix / master-rename.sh
Created June 15, 2020 10:42
Local script to rename master branch to main
#!/bin/bash
git checkout master
git pull
git branch -m master main
git push -u origin main
git checkout main
echo "Go to the repo Settings > Branches > Default Branch. Change it to the new branch press [ENTER]"
read finished