Skip to content

Instantly share code, notes, and snippets.

View leeyspaul's full-sized avatar
🍵
probably writing something.

Paul leeyspaul

🍵
probably writing something.
View GitHub Profile
@leeyspaul
leeyspaul / Looping Triangle
Created February 23, 2016 00:44
JavaScript Looping Triangle Exercise
for ( var y = "#"; y.length <= 7; y += "#" ) {
console.log(y);
}
@leeyspaul
leeyspaul / intro.md
Created November 18, 2016 09:11 — forked from gschema/intro.md
Basic JavaScript MVC Implementation

Basic JavaScript MVC Implementation

Despite being derived from classical MVC pattern JavaScript and the environment it runs in makes Javascript MVC implementation have its own twists. Lets see how typical web MVC functions and then dive into simple, concrete JavaScript MVC implementation.

How Web MVC typically works

Typical server-side MVC implementation has one MVC stack layered behind the singe point of entry. This single point of entry means that all HTTP requests, e.g. http://www.example.com or http://www.example.com/whichever-page/ etc., are routed, by a server configuration, through one point or, to be bold, one file, e.g. index.php.

At that point, there would be an implementation of Front Controller pattern which analyzes HTTP request (URI at first place) and based on it decides which class (Controller) and its method (Action) are to be invoked as a response to the request (method is name for function and member is name for a variable when part of the class/object).

@leeyspaul
leeyspaul / cDecipher.kt
Created July 31, 2018 23:16
Caeser Decipher in Kotlin
// Top level declaration of the alphabet array
val alphabet = arrayOf('a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
@leeyspaul
leeyspaul / unique_vocabs.py
Created July 31, 2018 23:18
Unique Vocab Generator for Facebook bABI Project (Snippet - Missing other parts)
def get_unique_vocab(file_name):
with open(file_name,'r') as file:
raw_corpus = file.read()
tokenized = text_to_word_sequence(raw_corpus, filters='\n\t?123456789101112131415.')
return set(tokenized + ['.'])
vocab = get_unique_vocab(task_training)
print(f'Vocabulary set\n---\n {vocab}')
@leeyspaul
leeyspaul / txt_to_raw.py
Created July 31, 2018 23:20
Generate .txt file to raw corpus (Code snippet)
def txt_to_raw(file_name):
'''
take in a file_name and then return a raw String corpus of the contained text
'''
with open(file_name, 'r') as file:
raw_corpus = file.readlines()
return raw_corpus
task_training_corpus = txt_to_raw(task_training)
task_testing_corpus = txt_to_raw(task_testing)
@leeyspaul
leeyspaul / v1.py
Last active July 31, 2018 23:34
Final project v1. (Inspiration from babi_rnn by Keras team - Taken from Jupyter Notebook)
import os
import numpy as np
import pandas as pd
from keras.preprocessing.text import text_to_word_sequence, Tokenizer
from keras.preprocessing.sequence import pad_sequences
from keras.models import Sequential, Model
from keras.layers import Dense, Flatten, Embedding, Input, Concatenate, Add, RepeatVector, RNN, LSTM, Dot, Dropout
from keras.optimizers import Adam, SGD
from keras.metrics import categorical_accuracy
from itertools import chain
@leeyspaul
leeyspaul / flow.py
Last active November 30, 2021 17:44
OAuth2 Flow Object Construction
# set up a Flow object that reads the clients from our secrets file with the
# corresponding scope
flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
'client_secrets.json',
scopes=['https://www.googleapis.com/auth/calendar'])
# indicate the redirect URI that we placed in the console redirect URI when we
# created the oauth credentials
flow.redirect_uri = 'http://localhost:8080/oauth2redirect'
@leeyspaul
leeyspaul / app.py
Created November 30, 2021 17:44
OAuth2 Google Calendar API Full Example
import flask
import google.oauth2.credentials
import google_auth_oauthlib.flow
import os
from flask import Flask
from flask import redirect
from flask import request
from googleapiclient.discovery import build
# set up a Flow object that reads the clients from our secrets file with the
@leeyspaul
leeyspaul / auth.py
Last active November 30, 2021 17:57
OAuth2 Google Calendar API Authorize Route
# create our Flask web app
app = Flask(__name__)
# this allows transport over HTTP for development purposes, if excluded
# HTTPS is needed
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
@app.route("/authorize-user")
def auth_user():
"""
@leeyspaul
leeyspaul / auth.py
Created November 30, 2021 20:16
OAuth2 Authorize Route for Google Calendar API
import flask
import google.oauth2.credentials
import google_auth_oauthlib.flow
import os
from flask import Flask
from flask import redirect
from flask import request
from googleapiclient.discovery import build
# set up a Flow object that reads the clients from our secrets file with the