Skip to content

Instantly share code, notes, and snippets.

View melvinkcx's full-sized avatar

Melvin Koh melvinkcx

View GitHub Profile
@melvinkcx
melvinkcx / models.py
Created September 11, 2018 14:05
Reducing Memory Footprint When Creating Archive in Django
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 January 28, 2019 12:50
Firebase Auth Using Facebook In Expo
// 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 December 31, 2018 08:59
Firebase Auth Using Facebook In Expo
// 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 December 31, 2018 09:00
Firebase Auth Using Facebook In Expo
{
"expo": {
...
"extra": {
"firebase": {
"apiKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"authDomain": "xxxxxxxxxx.firebaseapp.com",
"databaseURL": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
"projectId": "xxxxxxxxxx",
"storageBucket": "xxxxxxxxxx.appspot.com",
@melvinkcx
melvinkcx / title.model.js
Last active January 14, 2019 14:06
Dive Into The Performance of mongoose-lean-virtuals - A Mongoose Plugin That Enables Virtuals in Lean Mode
// 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 January 14, 2019 14:13
Dive Into The Performance of mongoose-lean-virtuals - A Mongoose Plugin That Enables Virtuals in Lean Mode
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 January 14, 2019 15:01
Enabling Virtuals In Mongoose Lean Mode (in a FeathersJs service)
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 January 14, 2019 15:08
Enabling Virtuals In Mongoose Lean Mode (in a FeathersJs service)
// 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 April 9, 2019 00:23
VSCode Debugger Configuration - Run yarn test
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Run yarn test",
"runtimeExecutable": "yarn",
"runtimeArgs": [
"test"
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)