Skip to content

Instantly share code, notes, and snippets.

Ethan Liew ethanliew

View GitHub Profile
@ethanliew
ethanliew / Mac OS X: Open in Visual Studio Code
Last active Jul 16, 2020 — forked from tonysneed/Mac OS X: Open in Visual Studio Code
Add a command to Finder services in Mac OSX to open a folder in VS Code
View Mac OS X: Open in Visual Studio Code
- Open Automator
- File -> New -> Quick Action
- Change "Workflow Receives current" to "files or folders" in "Finder"
- Add a "Run Shell Script" action
- Change "Pass input" to "as arguments"
- Paste the following in the shell script box: open -n -b "com.microsoft.VSCode" --args "$*"
- Save it as something like "Open in VSCode"
@ethanliew
ethanliew / convert id_rsa to pem
Created Jun 24, 2020 — forked from mingfang/convert id_rsa to pem
Convert id_rsa to pem file
View convert id_rsa to pem
openssl rsa -in ~/.ssh/id_rsa -outform pem > id_rsa.pem
chmod 600 id_rsa.pem
View google-domains-dynamic-dns-update.sh
#!/bin/bash
### Google Domains provides an API to update a DNS "Syntheitc record". This script
### updates a record with the script-runner's public IP, as resolved using a DNS
### lookup.
###
### Google Dynamic DNS: https://support.google.com/domains/answer/6147083
### Synthetic Records: https://support.google.com/domains/answer/6069273
USERNAME=""
@ethanliew
ethanliew / aggregation_lookup.md
Created Feb 11, 2020 — forked from bertrandmartel/aggregation_lookup.md
MongoDB $lookup aggregation example
View aggregation_lookup.md

MongoDB $lookup aggregation

SO link

db.votes.aggregate([{
    $lookup: {
        from: "users",
        localField: "createdBy",
        foreignField: "_id",
@ethanliew
ethanliew / beerSchema.js
Created Dec 12, 2019 — forked from suissa/beerSchema.js
Creating models dynamically
View beerSchema.js
var mongoose = require('mongoose');
var BeerSchema = new mongoose.Schema({
id: { type: Number, min: 0},
name: { type: String, default: '' },
description: { type: String, default: '' },
abv: { type: Number, min: 0},
category: { type: String, default: ''},
created_at: { type: Date, default: Date.now },
updated_at: { type: Date, default: Date.now }
@ethanliew
ethanliew / axios-catch-error.js
Created Dec 6, 2019 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
View axios-catch-error.js
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
@ethanliew
ethanliew / main.dart
Created Sep 23, 2019 — forked from branflake2267/main.dart
Flutter - Display the SnackBar using the GlobalKey
View main.dart
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
View recaptcha-final-angular.directive.ts
import { AfterViewInit, Directive, ElementRef, EventEmitter, forwardRef, Inject, Injectable, InjectionToken, Injector, Input, NgZone, OnInit, Output } from '@angular/core';
import { AbstractControl, ControlValueAccessor, FormControl, NG_VALUE_ACCESSOR, NgControl, Validators } from '@angular/forms';
import { Http } from '@angular/http';
declare const grecaptcha : any;
declare global {
interface Window {
grecaptcha : any;
reCaptchaLoad : () => void
@ethanliew
ethanliew / Post.php
Created Jul 20, 2019 — forked from fredyounan/Post.php
Eloquent boot method
View Post.php
class Post extends Eloquent {
/**
* This is a useful switch to temporarily turn of automatic model validation.
*/
public static $autoValidate = true;
/**
* The rules to use for the model validation.
* Define your validation rules here.
@ethanliew
ethanliew / hosts
Created Jun 24, 2019 — forked from consti/hosts
/etc/hosts to block shock sites etc.
View hosts
# This hosts file is brought to you by Dan Pollock and can be found at
# http://someonewhocares.org/hosts/
# You are free to copy and distribute this file for non-commercial uses,
# as long the original URL and attribution is included.
#<localhost>
127.0.0.1 localhost
127.0.0.1 localhost.localdomain
255.255.255.255 broadcasthost
::1 localhost
You can’t perform that action at this time.