Skip to content

Instantly share code, notes, and snippets.

@tzechienchu
tzechienchu / json.js
Created August 10, 2016 01:59 — forked from geuis/json.js
Better error handling for JSON.parse (javascript)
(function(){
var parse = JSON.parse;
JSON = {
stringify: JSON.stringify,
validate: function(str){
@tzechienchu
tzechienchu / ec2.js
Created August 26, 2016 09:58 — forked from d5/ec2.js
AWS Node.js SDK; EC2 instance creation and termination example
var aws = require('aws-sdk');
aws.config.update({
accessKeyId: 'YOUR_ACCESS_KEY',
secretAccessKey: 'YOUR_SECRET_KEY',
region: 'us-west-2'
});
var ec2 = new aws.EC2();
@tzechienchu
tzechienchu / stringify.js
Created September 1, 2016 06:20 — forked from cowboy/stringify.js
JavaScript: like JSON.stringify but handles functions, good for creating arbitrary .js objects?
var stringify = function(obj, prop) {
var placeholder = '____PLACEHOLDER____';
var fns = [];
var json = JSON.stringify(obj, function(key, value) {
if (typeof value === 'function') {
fns.push(value);
return placeholder;
}
return value;
}, 2);
@tzechienchu
tzechienchu / Javascript ISO country code to country name conversion
Created September 23, 2016 04:45 — forked from maephisto/Javascript ISO country code to country name conversion
ISO 3166-1 alpha-2 country code to country name conversion with a simple Javascript implementation, an array and a function.
var isoCountries = {
'AF' : 'Afghanistan',
'AX' : 'Aland Islands',
'AL' : 'Albania',
'DZ' : 'Algeria',
'AS' : 'American Samoa',
'AD' : 'Andorra',
'AO' : 'Angola',
'AI' : 'Anguilla',
'AQ' : 'Antarctica',
@tzechienchu
tzechienchu / disableAllMethods.js
Created October 13, 2016 09:49 — forked from ratik/disableAllMethods.js
LoopbackJs disable all remote methods and enable only selected
/**
* Based on @ericprieto code https://github.com/strongloop/loopback/issues/651#issuecomment-140879983
* place this file into common/mixins/disableAllMethods.js
*
**/
module.exports = function(Model, options) {
if(Model && Model.sharedClass) {
var methodsToExpose = options.expose || [];
@tzechienchu
tzechienchu / readme.md
Created December 29, 2016 07:18 — forked from glennschler/readme.md
AWS Docker VPN

Using AWS Linux setup an L2TP/IPSEC Soft Ether VPN

Consider HVM (SSD) EBS-Backed 64-bit m3.medium

  • us-east-1 => ami-1ecae776

  • Updates and dependencies

sudo yum -y update
sudo yum -y upgrade
sudo yum -y install docker git wget
@tzechienchu
tzechienchu / DisableAllMethods.js
Created October 26, 2017 02:01 — forked from drmikecrowe/DisableAllMethods.js
Loopback mixin to disable or expose methods
// based on https://github.com/strongloop/loopback/issues/651#issuecomment-259540469
'use strict';
const
relationMethodPrefixes = [
'prototype.__findById__',
'prototype.__destroyById__',
'prototype.__updateById__',
'prototype.__exists__',
@tzechienchu
tzechienchu / mbp2011-disable-amd-gpu.md
Created July 17, 2018 07:55 — forked from blackgate/mbp2011-disable-amd-gpu.md
Macbook Pro 2011 - Disable AMD GPU
@tzechienchu
tzechienchu / Markdown教學.md
Created July 18, 2018 03:44 — forked from christech1117/Markdown教學.md
Markdown教學,每個部分的教學分為兩個區塊,上半部為markdown語法,下半部為顯示結果
@tzechienchu
tzechienchu / mongodb-s3-backup.sh
Created October 16, 2018 04:14 — forked from eladnava/mongodb-s3-backup.sh
Automatically backup a MongoDB database to S3 using mongodump, tar, and awscli (Ubuntu 14.04 LTS)
#!/bin/sh
# Make sure to:
# 1) Name this file `backup.sh` and place it in /home/ubuntu
# 2) Run sudo apt-get install awscli to install the AWSCLI
# 3) Run aws configure (enter s3-authorized IAM user and specify region)
# 4) Fill in DB host + name
# 5) Create S3 bucket for the backups and fill it in below (set a lifecycle rule to expire files older than X days in the bucket)
# 6) Run chmod +x backup.sh
# 7) Test it out via ./backup.sh