Skip to content

Instantly share code, notes, and snippets.

View iJKTen's full-sized avatar
🔥

JK iJKTen

🔥
View GitHub Profile
burn = stash
st = status
cm = commit -m
cu = commit --amend -m
a = add .
new = checkout -b
del = branch -D
br = branch --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) %(color:green)(%(committerdate:relative)) [%(authorname)]' --sort=-committerdate
done = push origin HEAD
# Add everything to be commited
git add .
# Commit all the changes
git commit -m "message"
# Add everything and commit in one line
git commit -am "message"
# Create a new branch from main

Query an array of embedded documents

If your inventosy document has the following data and you want to get all the warehouses with a value of 'A'

db.inventory.insertMany( [
   { item: "journal", instock: [ { warehouse: "A", qty: 5 }, { warehouse: "C", qty: 15 } ] },
   { item: "notebook", instock: [ { warehouse: "C", qty: 5 } ] },
   { item: "paper", instock: [ { warehouse: "A", qty: 60 }, { warehouse: "B", qty: 15 } ] },
   { item: "planner", instock: [ { warehouse: "A", qty: 40 }, { warehouse: "B", qty: 5 } ] },
 { item: "postcard", instock: [ { warehouse: "B", qty: 15 }, { warehouse: "C", qty: 35 } ] }
arr = []
// Another way to declare an array
arr = Array.new
arr.push(1)
# append is an alias for push
arr.append(2)
var arr = [1, 2, 3, 4]
// Another way to create an empty array of integers
var arr: [Int] = []
// Long way to create an empty array of integers
var arr: Array<Int> = Array()
// Create a new array with a size and a default value of 0 for all the elements
var arr = Array(repeating: 0, count: 8)
arr = []
arr.append(1)
arr.append(2)
arr.insert(2, 3)
arr.insert(3, 4)
# Add elements with a for loop
for index in range(4):
arr.append(index + 5)
// Declare an array without a size
const arr = [];
// Declrate an array with a size
const arr2 = new Array(8);
console.log({"typeOfArr": typeof arr});
console.log({"typeOfArr2": typeof arr2});
// Populate array arr
@iJKTen
iJKTen / array.js
Last active May 31, 2020 22:33
Array Basics
// Declare an array
const arr = [10, 20, 4, 50];
// Output the array
console.log({arr});
// Get the element at the first position
// You index into the array with the help of square brackets.
const firstElement = arr[0]
To create a new app using postgresql
> rails new app-name -d postgresql
rails new -h will display different options you can use with rails new
To create a new project with prompts
> npm init
To create a new project without prompts
> npm init -y
Install a package (will be used in production)
> npm install <package-name>
Installing a dev package