Skip to content

Instantly share code, notes, and snippets.

View euclid1990's full-sized avatar
🍔
Code for food

Nguyen Van Vuong (Vic) euclid1990

🍔
Code for food
View GitHub Profile
@euclid1990
euclid1990 / app.js
Last active August 29, 2015 14:11 — forked from alfredwesterveld/app.js
var express = require('express'),
app = express.createServer(),
sio = require('socket.io'),
redis = require("redis"),
client = redis.createClient(),
io = null;
/**
* Used to parse cookie
*/
@euclid1990
euclid1990 / Ansible-Vault how-to.md
Created July 31, 2016 15:21 — forked from tristanfisher/Ansible-Vault how-to.md
A short tutorial on how to use Vault in your Ansible workflow. Ansible-vault allows you to more safely store sensitive information in a source code repository or on disk.

##Working with ansible-vault

I've been using a lot of Ansible lately and while almost everything has been great, finding a clean way to implement ansible-vault wasn't immediately apparent.

What I decided on was the following: put your secret information into a vars file, reference that vars file from your task, and encrypt the whole vars file using ansible-vault encrypt.

Let's use an example: You're writing an Ansible role and want to encrypt the spoiler for the movie Aliens.

@euclid1990
euclid1990 / child.js
Created March 19, 2017 06:09 — forked from brugnara/child.js
fork vs spawn, nodejs
var i = 0;
setInterval(function() {
if (i++ % 2) {
console.log('I\'m the child!');
} else {
console.error('I\'m the child!');
}
}, 1500);
@euclid1990
euclid1990 / php2js-curl-basic-auth.js
Created March 21, 2017 06:11 — forked from kostasx/php2js-curl-basic-auth.js
PHP to Node.js: cURL with Basic Authentication
/*
<?php
// THE FOLLOWING IMPLEMENTATION CAN BE USED FOR VARIOUS APIs. THIS WAS TESTED SUCCESSFULLY ON THE pingdom.com API
$email = "your@mail.net";
$passwd = 'password';
$api_key = "API_KEY";
$curl = curl_init();
@euclid1990
euclid1990 / site.js
Last active April 21, 2017 08:08
Detect Local IP Address - Web RTC
/*! jQuery v1.10.1 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license
*/
(function(e, t) {
var n, r, i = typeof t, o = e.location, a = e.document, s = a.documentElement, l = e.jQuery, u = e.$, c = {}, p = [], f = "1.10.1", d = p.concat, h = p.push, g = p.slice, m = p.indexOf, y = c.toString, v = c.hasOwnProperty, b = f.trim, x = function(e, t) {
return new x.fn.init(e,t,r)
}
, w = /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source, T = /\S+/g, C = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, N = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/, k = /^<(\w+)\s*\/?>(?:<\/\1>|)$/, E = /^[\],:{}\s]*$/, S = /(?:^|:|,)(?:\s*\[)+/g, A = /\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g, j = /"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g, D = /^-ms-/, L = /-([\da-z])/gi, H = function(e, t) {
return t.toUpperCase()
}
, q = function(e) {
@euclid1990
euclid1990 / CentOS6-L2TP-IPsec.md
Created September 1, 2017 05:52 — forked from CLCL/CentOS6-L2TP-IPsec.md
L2TP/IPsec(AndroidやiPhoneからのVPN接続)を経路を用意すべくVPSにL2TP/IPsecサーバを設置するとき、ネットにある情報だとなかなかつながらないから、標準環境としてAWSのCentOS 6.3 x86_64 Release Media(ami-3fe8603e)の起動直後から最短距離で設定する方法をまとめた。

CentOS 6でとにかくL2TP/IPsecサーバ

  • AWSでEC2のインスタンスを借りる
  • 今回は東京リージョンのCentOS 6.3 x86_64 Release MediaのAIM(ami-3fe8603e)でインスタンスを建てる
  • Security Group: L2TP/IPsec(Inbound 22/TCP: SSH, 500/UDP: ISAKMP, 1701/UDP: L2TP, 4500/UDP: IPSec NAT Traversal)を許可
  • ec2-54-249-173-214.ap-northeast-1.compute.amazonaws.com(グローバルIPアドレス:54.249.173.214)にrootでログイン

SELinuxを無効にする

[root@ip-10-132-164-105 ~]# setenforce 0
@euclid1990
euclid1990 / Large-app-how-to.md
Created September 1, 2017 07:06 — forked from cuibonobo/Large-app-how-to.md
How to structure a large application in Flask. Taken from the Flask wiki: https://github.com/mitsuhiko/flask/wiki/Large-app-how-to

Here's an example application that uses the pattern detailed below: https://github.com/tantastik/talent-curator


This document is an attempt to describe the first step of a large project structure with flask and some basic modules:

  • SQLAlchemy
  • WTForms

Please feel free to fix and add your own tips.

@euclid1990
euclid1990 / README.md
Created September 5, 2017 07:44 — forked from rduplain/README.md
Flask-Script: demo passing in configuration file.

This demonstrates that you can configure a Flask application through Flask-Script, without having to create a Flask instance or deal with circular dependencies. Note that Flask-Script's Manager accepts a factory function in place of a Flask app object.

Running:

python manage.py runserver

gives "Hello, world!" on http://localhost:5000/, while running:

python manage.py runserver -c development.cfg
@euclid1990
euclid1990 / audit_mixin.py
Created September 13, 2017 06:38 — forked from ngse/audit_mixin.py
Rough attempt at implementing an audit log against Flask/Flask Login/SQLAlchemy models
# Requires use of Flask Login for the user tracking
# Implement by using AuditableMixin in your model class declarations
# e.g. class ImportantThing(AuditableMixin, Base):
import json
from flask_login import current_user
from sqlalchemy import event, inspect
from sqlalchemy.orm import class_mapper
from sqlalchemy.orm.attributes import get_history
@euclid1990
euclid1990 / meta.py
Created September 14, 2017 04:57 — forked from shazow/meta.py
My latest SQLAlchemy model base class.
"""SQLAlchemy Metadata and Session object"""
import datetime
import json
import time
from sqlalchemy import MetaData
from sqlalchemy.orm import scoped_session, sessionmaker
__all__ = ['Session', 'metadata', 'Model', 'SchemaEncoder']