Skip to content

Instantly share code, notes, and snippets.

View ethanliew's full-sized avatar

Ethanz Liew ethanliew

View GitHub Profile
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
void main() => runApp(ExampleApp());
class ExampleApp extends StatelessWidget {
@override
@ethanliew
ethanliew / setup.md
Created June 22, 2019 05:12 — forked from developius/README.md
Set up GitHub push with SSH keys

Create a repo. Make sure there is at least one file in it (even just the README) Generate ssh key:

ssh-keygen -t rsa -C "your_email@example.com"

Copy the contents of the file ~/.ssh/id_rsa.pub to your SSH keys in your GitHub account settings. Test SSH key:

ssh -T git@github.com
@ethanliew
ethanliew / hosts
Created June 24, 2019 04:46 — forked from consti/hosts
/etc/hosts to block shock sites etc.
# 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
@ethanliew
ethanliew / Post.php
Created July 20, 2019 11:14 — forked from fredyounan/Post.php
Eloquent boot method
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.
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 / main.dart
Created September 23, 2019 10:26 — forked from branflake2267/main.dart
Flutter - Display the SnackBar using the GlobalKey
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(
@ethanliew
ethanliew / axios-catch-error.js
Created December 6, 2019 01:25 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
/*
* 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 / beerSchema.js
Created December 12, 2019 07:56 — forked from suissa/beerSchema.js
Creating models dynamically
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 / aggregation_lookup.md
Created February 11, 2020 03:18 — forked from bertrandmartel/aggregation_lookup.md
MongoDB $lookup aggregation example

MongoDB $lookup aggregation

SO link

db.votes.aggregate([{
    $lookup: {
        from: "users",
        localField: "createdBy",
        foreignField: "_id",
@ethanliew
ethanliew / google-domains-dynamic-dns-update.sh
Created March 10, 2020 14:07 — forked from cyrusboadway/google-domains-dynamic-dns-update.sh
Script to update a Google Domains DNS record
#!/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=""