Skip to content

Instantly share code, notes, and snippets.

View gwuah's full-sized avatar
🎯
Focusing

Kwaw gwuah

🎯
Focusing
View GitHub Profile

Rust Module System

The rust compiler makes little/no assumptions about the structure of your project. You’re required to construct your entire module tree yourself. To make our work easy, it provides us with some building blocks for this construction

The rust module systems works similar to modern filesystems. There’s a parent & some children. That said, rust has a unique way of doing everything you already know, so I’ll advice you approach this note on a blank state and try to draw parallels later.

@gwuah
gwuah / file-downloader.go
Last active February 2, 2021 10:01
file-downloader
package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
"time"
const {router} = require("ottis");
/* Using our router, we declare permissions for admin role */
const admin = {
/* define permissions on customer resource */
customers: [router("*").all()],
/* define permissions on anonymous-customer resource */
anonymousCustomers: [router("*").all()],
/* define permissions on products resource */
products: [
/*
ottisConfig.js will be created later.
but for now lets' assume it contains
our configurations/permissions.
*/
const User = require('./ottisConfig');
const requestObj = {}; // http request object
// this returns either true or false.
const Ottis = require('Ottis');
const router = Ottis.router;
/* easily declare your route permissions. */
/* can make only post, get, and put requests to /users */
router("/users").post().get().put().done();
/* can make any type of http request to /users */
router("/products").all();
const User = require('./authConfig.js');
function authorizeRequestTo(resource) {
return (req, res, next) {
/*
This is all on you. You can decide to populate
the user's rolename on a different variable
(other than roleName). This just an example.
*/
const roleName = req.user.role.toLowercase();
const Ottis = require('../lib');
const router = Ottis.router;
const {admin, customer} = require('./permissions');
/* Initialise Ottis with various roles */
const auth = Ottis(["admin","customer"]);
/* Admin Config */
auth.addConfigFor('admin').forResource('customers')({
config: admin.customers
@gwuah
gwuah / ewew.py
Created July 28, 2018 15:02
trtrt
​x1this ins markdownjshdsjusudfdufgudggfdf
@gwuah
gwuah / hello_world.py
Created July 28, 2018 06:06
Hello World Examples
class HelloWorld:
def __init__(self, name):
self.name = name.capitalize()
def sayHi(self):
print "Hello " + self.name + "!"
hello = HelloWorld("world")
hello.sayHi()
@gwuah
gwuah / cart.js
Last active May 30, 2018 11:19
A simple cart store that can be used to persist state across all components and pages. no need VueX
import Vue from 'vue';
export const Store = new Vue({
data: function () {
return {
cart: [],
tax: 0,
totalItemsInCart: 0
}
},