Skip to content

Instantly share code, notes, and snippets.

View j178's full-sized avatar
🕶️
Living

Jo j178

🕶️
Living
View GitHub Profile
@j178
j178 / main.go
Last active July 1, 2023 10:00
Gin route confliction
package main
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
r.GET("/users/:name", func(c *gin.Context) {})
// can't use `:id` here, change to `:name` will fix the confliction
r.GET("/users/:id/repos", func(c *gin.Context) {})
_ = r.Run(":8080")
@j178
j178 / bench_bool_to_string.cpp
Last active April 11, 2023 11:36
Compile with `g++ -std=c++11 -O2 bench.cpp -o bench`
#include <iostream>
#include <chrono>
#include <sstream>
using namespace std;
using namespace chrono;
// Method 1: Using a conditional operator
string bool_to_string_conditional(bool b) {
return b ? "true" : "false";

Galaxy Brain

Galaxy Brain Badge

这个徽章需要由你在 Discussion Q&A 中回答别人的问题,并且由 OP(不能是你自己)mark as answer 才能获得。需要至少回答两个问题。

Pair Extraordinaire

Pair Extraordinaire Badge

from threading import Event, Thread
event1 = Event()
event2 = Event()
event3 = Event()
i = 0
def f1():
global i
@j178
j178 / github_batch_block.py
Last active December 19, 2019 12:11
批量 block 用中文污染 issue 的人
# -*- coding: utf-8 -*-
# Created by johnj at 2019/12/19
"""
批量 block 用中文污染 issue 的人
需要设置 USERNAME 和 TOKEN 两个环境变量
USERNAME 为 GitHub 用户名
TOKEN 获取参考这里:# https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line
"""
<?php
return sg_load('0A01FEFE4CDFE8DCAAQAAAAXAAAABGgAAACABAAAAAAAAAD/sFFonI5E/xv0Nvko1nt1cGvdcCQ4+0AB/9a1drcirnIeprf0fSXAGndgenGD2Ms2f8fi/9yfLRReY4diC1jorYd5LwPpUowSHZHD8Dd099AqqgbALH0AB3A3LUKyPQ7926nUlY7+bY5HAAAA0HoAACjRDNeVsiYzLV1PKBsL2t0MHQ775l6xpFj0FHgJGti7Iw/EPyzMdwTvZH4jkwKfkqg89CmZy1pmn//8qYDSUHJsAgJt4hP48dl8mUPcqEIZKFZ3qT0DNHr8wDPOuvgq0xq+RMBafv/K7ePfEbsf+C5W43npf+BRBN/0f7iZQZvtRUz4X6VjoX4as0lMV85HztwDEVhlPKV8QHfnjLJqcgr2G3/+60Dpl7Zak8JiGdz5VALT4/Vskguk8fnpJvA2Y/B1a9hA67mWeXg+/c1VM1liU14LdPcq6dziVQ8ty9bWWWLHCj3Yr5gVL6rf3E1HuFiO3muXRUsJdRojOh4iaZVthuLwiyykAQeRVDBcfAhvXRkhA8SNrIE+3D37xVXZiyPeyo1LF24v/nu4aJdT5i4lVIVH1Z744NTxG9DUaMd7b7cLqG1KAaIW29YbOUSmLD7+PTdmsXwV1QWWLcQqxX6ppad8XUkYA0OlV6LAtnxoG+UdJzhfeZEsHnkXctM2VcLx6DhMHl7ZTfxVB9nyEqmumufWJzyamcQc2Ch7u7MlYY44TD+H177xzaua+CQlSS53gEmK/bxktKFqJc0XMWDKiaK/ooaQpfFD9yKTZ96AZ6smnwNJu3AcvGEuQv3/MuYWzkAvgcRteukU4mRI9I4yL0D+IIgmZWs++VecXElOEgPZvbRMUfAYRpp2LHvyv1Q95R3dkg3KlBrHLNFhFeaQ/uOw7jAl4LeN6EWDFaiWSY53Qde4b8tzkHC4PMFpHlCy6f4zKRBtet92D8sUR+w2inoTdz2pTyxpi5
@j178
j178 / Flask-SQLAlchemy Caching.md
Last active October 31, 2023 15:20 — forked from typehorror/Flask-SQLAlchemy Caching.md
Flask SQLAlchemy Caching

Flask-SQLAlchemy Caching

The following gist is an extract of the article Flask-SQLAlchemy Caching. It allows automated simple cache query and invalidation of cache relations through event among other features.

Usage

retrieve one object

# pulling one User object

user = User.query.get(1)

@j178
j178 / chrome_cookie.py
Last active August 22, 2018 03:28
Extract host cookies from Chrome cookie databse

Keybase proof

I hereby claim:

  • I am j178 on github.
  • I am j178 (https://keybase.io/j178) on keybase.
  • I have a public key ASDwwkUUC1UvGUF2DjZudNwJTDU-SrydNVpaIk4AudKdrQo

To claim this, I am signing this object:

#!/usr/bin/env python3
import base64
import random
import re
import string
import requests
sess = requests.Session()
randstr = lambda len=5: ''.join(random.choice(string.ascii_lowercase) for _ in range(len))