Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View hrchu's full-sized avatar
:octocat:
Have an Octotastic day!

petertc hrchu

:octocat:
Have an Octotastic day!
View GitHub Profile
@hrchu
hrchu / 1. basic flow with auth code and access token
Last active February 21, 2024 09:27
OAuth 2.0 / OpenID Connect flow diagrams. Build it by http://www.plantuml.com/plantuml/uml/
@startuml
skinparam handwritten true
"You/Browser" -> slack.com: 1. I would like to access my files on Google Drive via your interface.
slack.com -> "You/Browser": 2. You should apply the "Authorization Code" from Google for me first.
"You/Browser" -> account.google.com: 3. I would like to permit slack.com to access my files.
account.google.com -> "You/Browser": 4. Are you sure?
"You/Browser" -> account.google.com: 5. [Y]
account.google.com -> "You/Browser": 6. Okay. Here is the "Authorization Code." Plz give it back to slack.com now.
"You/Browser" -> slack.com: 7. You can do what I asked now (with the Authorization Code which is just received from Google.)
slack.com -> account.google.com: 8. I would like to exchange the "Authorization Code" for the "Access Token."
@hrchu
hrchu / 99-network-tuning.conf
Last active December 11, 2023 23:05 — forked from kgriffs/sysctl.conf
Linux Web Server Kernel Tuning
# Configuration file for runtime kernel parameters.
# See sysctl.conf(5) for more information.
# See also http://www.nateware.com/linux-network-tuning-for-2013.html for
# an explanation about some of these parameters, and instructions for
# a few other tweaks outside this file.
# See evil packets in your logs.
net.ipv4.conf.all.log_martians = 1
@hrchu
hrchu / gist:b53e12389d2e4b0d01ddd29fe4a4d9eb
Last active November 1, 2023 06:16
play solid_oidc_client
In [2]: from solid_oidc_client import SolidOidcClient, MemStore
...: solid_oidc_client = SolidOidcClient(storage=MemStore())
...: import requests
In [4]: issuer = 'https://login.inrupt.com/'
...: redirect_url = 'http://localhost:3333/oauth/callback'
...: solid_oidc_client.register_client(issuer, [redirect_url])
In [5]: login_url = solid_oidc_client.create_login_uri('/', redirect_url)
...: print(login_url)
@hrchu
hrchu / PlayPath.java
Created October 22, 2022 14:57
Relative path handling in Java
package org.example;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
public class PlayPath {
@hrchu
hrchu / mhVTL_install_ubuntu.sh
Last active September 19, 2022 19:57
mhVTL install script for Ubuntu 16.04 (tested on the kernel version that less or equal 4.15.0)
#!/bin/sh
# Script to download, compile and install mhvtl
# Tested on ubuntu 16.04
# Origin: http://mhvtl-a-linux-virtual-tape-library.966029.n3.nabble.com/Easy-Install-for-Debian-Ubuntu-td4025413.html
# 03/04/13
# Added libconfig-general-perl (ensures tgt-admin can run)
# 04/04/13
# Added line to append www-data to sudoers automatically
# Added check for sudo/root
# Added copy for tgt-admin in sbin (fixes persistant config in tgt mhvtl-gui)
@hrchu
hrchu / TestGson.java
Last active September 13, 2022 13:17
Convert Json from/to object/tree/inputstream/reader/file with Gson in Java
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import org.junit.jupiter.api.Test;
/**
* Convert Json from/to object/tree/inputstream/reader/file with Gson in Java
*
* ref https://www.javadoc.io/doc/com.google.code.gson/gson/2.9.0/com.google.gson/com/google/gson/Gson.html
@hrchu
hrchu / s3.py
Created February 24, 2022 02:34
s3 python util/example code
import logging
from typing import Iterable, Dict, BinaryIO
import boto3
from boto3.s3.transfer import TransferConfig
from botocore.config import Config
from botocore.exceptions import ClientError
KB = 1024
MB = KB * KB
@hrchu
hrchu / pycon-us-cfp.md
Last active December 8, 2021 12:47
Decentralized web application with Solid protocol

In 30mins, I will address crucial parts of implementing Solid in Python, so attendees can understand how to build a decentralized web application with Python and get the benefits of this promising architecture.

Overview: why we need decentralized web architecture and what does it look like in a Solid way?

In classical web architecture, application and data are bundled together, hence user data are naturally owned by service providers. This causes security, privacy, interoperability, and many other well-known issues for both users and service providers.

Service providers need to pay additional responsibility to protect user data in the scenario. Moreover, users cannot fully control and migrate their data without additional mechanisms provided by the service providers (GDPR tries to address this in a nontechnical way.)

With Solid, all personal data is stored in a data repository named Pod controlled by users. That could be set up on a user's server at home, or provided by a data storage supplier chos

@hrchu
hrchu / play-n3.ts
Created December 4, 2021 12:10
Use N3.js in TypeScript
// https://github.com/rdfjs/N3.js/
import {Parser, StreamParser, Writer} from "n3";
import * as fs from "fs";
import {DataFactory} from 'n3';
import {Writable} from 'stream';
function fromQualsToAString() {
const writer = new Writer({prefixes: {c: 'http://example.org/cartoons#'}});
const {namedNode, literal, defaultGraph, quad} = DataFactory;
@hrchu
hrchu / gen.py
Last active July 5, 2021 12:58
Python generator simple usage
def gen():
a = range(5)
for x in a:
yield x
x = gen() # instanlize
x.__next__() # get next
Out[36]: 0
next(x) # alternative way