Skip to content

Instantly share code, notes, and snippets.

View yosriady's full-sized avatar
💡
Optimize for Learning

Yos Riady yosriady

💡
Optimize for Learning
View GitHub Profile
[alias]
a = add . -A
st = status
cl = clone
ci = commit
c = commit -m
ca = commit --amend
br = branch
co = checkout
df = diff --word-diff
@yosriady
yosriady / .bash_prompt
Last active June 6, 2016 07:01
Bash prompt
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then export TERM=gnome-256color
elif [[ $TERM != dumb ]] && infocmp xterm-256color >/dev/null 2>&1; then export TERM=xterm-256color
fi
if tput setaf 1 &> /dev/null; then
tput sgr0
if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
MAGENTA=$(tput setaf 9)
ORANGE=$(tput setaf 172)
GREEN=$(tput setaf 190)
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Inlvcy5yaWFkeUBob2xtdXNrLmNvbSIsInVzZXJfaWQiOiJkMjMyNjNjZC0zMWJiLTRiMTItYjNjMC03NzZkODA2ZWZlZTIiLCJkZXZpY2VfaWQiOjF9.RFzN79tTzuvYwOn1V_9dVMDcl32qKPVpghvCMPMhLYM
@yosriady
yosriady / DESIGN.md
Last active February 17, 2024 15:08
OAuth2 Authentication Microservices Design

Auth

Disclaimer

Creating an OAuth2 server is not a task that should be taken lightly. There are many security loopholes that could be exploited, and regular examinations are critical to handle possible vulnerabilities.

Introduction

Auth is an authentication microservice based on the OAuth2 identity delegation protocol.

var express = require('express');
var morgan = require('morgan');
var http = require('http');
var mongo = require('mongodb').MongoClient;
var winston = require('winston');
// Logging
winston.emitErrs = true;
var logger = new winston.Logger({
transports: [
@yosriady
yosriady / TODO.md
Last active December 8, 2015 08:12
  • /login by email & password
  • /register by email & password
  • /passwords/forgot
  • /passwords/reset
  • /oauth/fb

2FA, if user logs in with a new device with a new device ids OR new IP we need to send them a otp via email to validate.

@yosriady
yosriady / data_source.py
Last active December 2, 2015 09:44
CS3219 Snippet
import abc
class DataSource(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def load(cls, filepath):
raise NotImplementedError('The load method takes in a filepath and \
returns data.')
@yosriady
yosriady / code.rb
Created November 30, 2015 13:04
CS3218 Snippet
module PgTags
module Taggable
def self.included(base)
base.extend(ClassMethod)
end
module ClassMethod
def has_tags(*tag_types)
tag_types = tag_types.to_a.flatten.compact.map(&:to_sym)

Some observations:

  • magicNumber=3 should be defined as a class constant with a proper name such as CERTIFIED_HOST_TRESHOLD, this way we can also skip the comment since the variable name is self-explanatory.
  • the Inquiry.find call and the if conditional expression should not be in the User class at all. It makes more sense to have a method within the Inquiry class that returns whther or not a host has the required number of inquiries.
  • Everytime we save, the before_save create_new_password callback is triggered and changes the user's password to a new password. I doubt this is intended behaviour. Do you mean before_create? I'm going to assume this example ignores resetting password use cases. If we only allow the password attribute to be set once on account creation, we could use read_attribute :password to prevent future tampering of the password attribute.
  • The raw SQL query is hard to read. Alternatively, we could do host.inquries.where(:status => [:status_1, :status_2]))
  • Usin
[
{"name": "Buy groceries", "completed": true},
{"name": "Finish homework", "completed": true},
{"name": "Launch startup", "completed": false}
]