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 / disable_proxy.sh
Created April 26, 2024 05:01
ubuntu HTTP proxy switch
#!/bin/bash
# Remove proxy settings for various protocols
unset http_proxy
unset https_proxy
unset ftp_proxy
unset rsync_proxy
# Remove proxy for apt (if exists)
sudo rm -f /etc/apt/apt.conf.d/99proxy
@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 / 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
18.04
apt install python3-pip
16.04
sudo apt-get install vim htop nmon ngrep iftop tmux dnsmasq curl ifstat iperf httpie python-virtualenv build-essential
@hrchu
hrchu / blink.py
Last active July 15, 2020 12:00
Blink LED on Raspberry Pi