Skip to content

Instantly share code, notes, and snippets.

Melvin Koh melvinkcx

Block or report user

Report or block melvinkcx

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@melvinkcx
melvinkcx / models.py
Created Sep 11, 2018
Reducing Memory Footprint When Creating Archive in Django
View models.py
from django.core.files.base import ContentFile
from django.db import models
file_storage = FileSystemStorage(location='/archive')
class MyFileModel(models.Model):
"""
A sample model
"""
@melvinkcx
melvinkcx / auth.js
Last active Jan 28, 2019
Firebase Auth Using Facebook In Expo
View auth.js
// Say this is /utils/auth.js
import firebase from './firebase'
export async function signInWithFacebook() {
const appId = Expo.Constants.manifest.extra.facebook.appId;
const permissions = ['public_profile', 'email']; // Permissions required, consult Facebook docs
const {
type,
token,
@melvinkcx
melvinkcx / firebase.js
Created Dec 31, 2018
Firebase Auth Using Facebook In Expo
View firebase.js
// In /utils/firebase.js
// We should import firebase from this module instead of the default package.
import * as firebase from 'firebase' // Should not be used elsewhere in the project
firebase.initializeApp(Expo.Constants.manifest.extra.firebase);
export default firebase;
@melvinkcx
melvinkcx / app.json
Created Dec 31, 2018
Firebase Auth Using Facebook In Expo
View app.json
{
"expo": {
...
"extra": {
"firebase": {
"apiKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"authDomain": "xxxxxxxxxx.firebaseapp.com",
"databaseURL": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
"projectId": "xxxxxxxxxx",
"storageBucket": "xxxxxxxxxx.appspot.com",
@melvinkcx
melvinkcx / title.model.js
Last active Jan 14, 2019
Dive Into The Performance of mongoose-lean-virtuals - A Mongoose Plugin That Enables Virtuals in Lean Mode
View title.model.js
// Full Repo: https://bitbucket.org/melvinkcx/mongoose_lean_virtuals_profiler/src/master/
const mongoose = require('mongoose');
const mongooseLeanVirtuals = require('mongoose-lean-virtuals');
const Schema = mongoose.Schema;
// Modelled after imdb title dataset
// Link: https://datasets.imdbws.com/title.basics.tsv.gz
const titleSchema = new Schema({
genres: String,
@melvinkcx
melvinkcx / index.js
Created Jan 14, 2019
Dive Into The Performance of mongoose-lean-virtuals - A Mongoose Plugin That Enables Virtuals in Lean Mode
View index.js
async function runProfiler(numberOfTimes, limit) {
const mongoose = require('mongoose');
const TitleModel = require('./title.model');
const mongodb = "mongodb://root:root@localhost/imdb?authSource=admin"
mongoose.connection.once('open', function () {console.log('connected to mongoDB');});
await mongoose.connect(mongodb, {useNewUrlParser: true})
mongoose.Promise = global.Promise;
@melvinkcx
melvinkcx / user.model.js
Created Jan 14, 2019
Enabling Virtuals In Mongoose Lean Mode (in a FeathersJs service)
View user.model.js
import mongooseLeanVirtuals from 'mongoose-lean-virtuals';
export default (app) => {
const mongooseClient = app.get('mongooseClient');
const {Schema} = mongooseClient;
const {ObjectId} = Schema.Types;
const user = new Schema({
// ...
});
@melvinkcx
melvinkcx / user.service.js
Last active Jan 14, 2019
Enabling Virtuals In Mongoose Lean Mode (in a FeathersJs service)
View user.service.js
// user.service.js
import createService from 'feathers-mongoose';
// other imports...
export default (app) => {
const Model = createModel(app);
// ...
const options = {
Model,
@melvinkcx
melvinkcx / launch.json
Last active Apr 9, 2019
VSCode Debugger Configuration - Run yarn test
View launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Run yarn test",
"runtimeExecutable": "yarn",
"runtimeArgs": [
"test"
View read_calendar_list.py
from google.oauth2 import service_account
from googleapiclient.discovery import build
SCOPES = ['https://www.googleapis.com/auth/calendar']
SERVICE_ACCOUNT_FILE = './xxxxxxxxxxxx.json' # You should make it an environment variable
credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
delegated_credentials = credentials.with_subject('melvin@xxxxxxxx.xx')
service = build('calendar', 'v3', credentials=delegated_credentials)
You can’t perform that action at this time.