Skip to content

Instantly share code, notes, and snippets.

Avatar

Jie Han jiehan1029

  • Cultivate AI
  • San Francisco Bay Area
View GitHub Profile
View Mongo basics drills.md

Get all

db.restaurants.find()

Limit and sort

Find the command that makes the first 10 restaurants appear when db.restaurants is alphabetically sorted by the name property.

db.restaurants.find().sort({name:1}).limit(10)

Get by _id

Retrieve a single restaurant by _id from the restaurants collection. This means you'll first need to get the _id for one of the restaurants imported into the database.

var id = db.restaurants.findOne()._id;

View run Nodejs server on AWS EC2 Linux.md

Install Node on EC2 and keep it running

This is the most straightforward way -- install node in the virtual server and simply keep it running. Good for testing, prototyping, etc. Obviously not for production.

First create a new EC2 instance (Amazon Linux AMI). SSH into it. Then install Node, install MongoDB or other database you'll be using, git clone your project repo, install dependencies, run the app, and finally make sure app will be running even if you close the terminal.

Install Node

You can follow the steps here (using NVM to install node): https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html

Or simply use yum to install node, as below.

View install MongoDB on AWS EC2 Linux.md
View Building on AWS.md

This is the note for AWS course 1 on edX. List selected AWS services in alphabetic order. Course link is here.

Workflow

Building on AWS --

  • Create VPC which simulates a local network that contains all your servers and databases.
  • Create IAM policy, user/role which has permission to specific AWS services, but not all -- this adds security overall.
  • Create S3 bucket (login as specific IAM user) which will be used to store assets.
  • Create RDS database instance (login as specific IAM user) as database server.
  • Create Cloud9 environment (login as specific IAM user) which is an online IDE that you can build & save your project.
  • Create EC2 instance (login as specific IAM user) and deploy the application via user data. This EC2 instance should have corresponding IAM role (to allow EC2 instance to call AWS service) and security group (to allow web t
View AWS IAM policy template.txt
// full access to AWS IAM, Amazon EC2, Amazon S3, Amazon RDS, Amazon SNS, Amazon SQS, Amazon Rekognition, AWS Lambda, Amazon Cognito, AWS Cloud9, AWS X-Ray, and AWS CloudFormation
// copy the following in JSON tab of the Create policy section
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Sid1",
"Effect": "Allow",
"Action": [
View AWS VPC template for CloudFormation.template
{
"Description": "Building on AWS VPC",
"Mappings": {
"AWSRegionToAMI": {
"us-west-2": {
"AMI": "ami-32cf7b4a"
}
}
},
"Resources": {
View AWS VPC template with NAT for CloudFormation.template
{
"Description": "Building on AWS VPC",
"Parameters": {
"KeyName": {
"Description": "Choose an existing EC2 KeyPair",
"Type": "AWS::EC2::KeyPair::KeyName"
}
},
"Mappings": {
"AWSRegionToAMI": {
@jiehan1029
jiehan1029 / download-opensans.sh
Created Jan 17, 2019 — forked from JamieMason/download-opensans.sh
Download all OpenSans fonts from Google Fonts
View download-opensans.sh
#!/usr/bin/env bash
wget -O src/assets/web-fonts/opensans/opensans-light_cyrillic-ext_normal_300 https://fonts.gstatic.com/s/opensans/v13/DXI1ORHCpsQm3Vp6mXoaTQ7aC6SjiAOpAWOKfJDfVRY.woff2
wget -O src/assets/web-fonts/opensans/opensans-light_cyrillic_normal_300 https://fonts.gstatic.com/s/opensans/v13/DXI1ORHCpsQm3Vp6mXoaTRdwxCXfZpKo5kWAx_74bHs.woff2
wget -O src/assets/web-fonts/opensans/opensans-light_greek-ext_normal_300 https://fonts.gstatic.com/s/opensans/v13/DXI1ORHCpsQm3Vp6mXoaTZ6vnaPZw6nYDxM4SVEMFKg.woff2
wget -O src/assets/web-fonts/opensans/opensans-light_greek_normal_300 https://fonts.gstatic.com/s/opensans/v13/DXI1ORHCpsQm3Vp6mXoaTfy1_HTwRwgtl1cPga3Fy3Y.woff2
wget -O src/assets/web-fonts/opensans/opensans-light_vietnamese_normal_300 https://fonts.gstatic.com/s/opensans/v13/DXI1ORHCpsQm3Vp6mXoaTfgrLsWo7Jk1KvZser0olKY.woff2
wget -O src/assets/web-fonts/opensans/opensans-light_latin-ext_normal_300 https://fonts.gstatic.com/s/opensans/v13/DXI1ORHCpsQm3Vp6mXoaTYjoYw3YTyktCCer_ilOlhE.woff2
wget -O src/as
@jiehan1029
jiehan1029 / base.css
Created Feb 12, 2019
reserved stylesheet base including normalization and bootstrap grid system
View base.css
@import url('https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800');
/* 1. css normalization; 2. customize default form; 3. customize default table; 4. customize default a and font; 5. bootstrap grid (and hide/show) layout classes and modal classes; 6. bootstrap helper classes; 7. overrides css of other modules in use if necessary; 8. customize buttons; 9. customize layout classes; 10. customize helper classes; 11. cutomize specific/one-time classes */
/* breakpoints at: min-width: (320),(468),576, 768, 992, 1200*/
/****************** normalize ******************/
html {
height: 100%;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
font-size: 10px;
-webkit-tap-highlight-color: transparent;
View Apps Script Gmail Utilities.md

Google Apps Script Gmail Utilities

##sendAndLabel(recipient, subject, body, options, label)##

An alternative to GmailApp.sendEmail(), which applies a label to the message thread in the sender's account.

Sends an email message with optional arguments. The email can contain plain text or an HTML body. The size of the email