Skip to content

Instantly share code, notes, and snippets.

import io
import selectors
import subprocess
import sys
def capture_subprocess_output(subprocess_args):
# Start subprocess
# bufsize = 1 means output is line buffered
# universal_newlines = True is required for line buffering
process = subprocess.Popen(subprocess_args,
@relyky
relyky / JsonSerializer.cs
Last active April 24, 2024 07:33
JsonSerializer, .NET5, json, 中文字不編碼, 換行與縮排, System.Text.Json, Indent
using System;
using System.Text.Json;
var foo = new { ... };
string json = JsonSerializer.Serialize(foo, new JsonSerializerOptions {
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping, // 中文字不編碼
WriteIndented = true // 換行與縮排
});
@SunMarc
SunMarc / finetune_llama_gptq.py
Last active April 24, 2024 07:33
Finetune GPTQ model with peft and tlr
# coding=utf-8
# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@avelardi
avelardi / branchscope-en.md
Last active April 24, 2024 07:31
Branchscope

BranchScope Article memo by herumi

Original here, just run through Google Translate and fixed formatting.

Whitepaper: BranchScope: A New Side-ChannelAttack on Directional Branch Predictor

Caution: I still do not understand the essential part

  • I might update it (maybe I can not dig into anymore because the condition that can be attacked is too severe to think that it is usually impossible)

Overview

@dabodamjan
dabodamjan / MailComposeViewController.swift
Last active April 24, 2024 07:31
Sending a contact us email on iOS 14 (can be also used with SwiftUI)
//
// Feel free to use this code in your project.
// Inspired by SO answer https://stackoverflow.com/a/65743126
// Uses DeviceKit as a dependency https://github.com/devicekit/DeviceKit
//
import Foundation
import MessageUI
import DeviceKit
@Kaligula0
Kaligula0 / YouTube_URLs.regexp
Last active April 24, 2024 07:30
A RegExp that matches all valid YouTube video URLs.
^(?:(?:https?:)?\/\/)?(?:(?:(?:www|m(?:usic)?)\.)?youtu(?:\.be|be\.com)\/(?:shorts\/|live\/|v\/|e(?:mbed)?\/|watch(?:\/|\?(?:\S+=\S+&)*v=)|oembed\?url=https?%3A\/\/(?:www|m(?:usic)?)\.youtube\.com\/watch\?(?:\S+=\S+&)*v%3D|attribution_link\?(?:\S+=\S+&)*u=(?:\/|%2F)watch(?:\?|%3F)v(?:=|%3D))?|www\.youtube-nocookie\.com\/embed\/)([\w-]{11})[\?&#]?\S*$
@bzvyagintsev
bzvyagintsev / README.md
Last active April 24, 2024 07:30
Шаблон README.md

Название проекта

Добавьте краткое описание проекта, опишите какую задачу он решает. 1-3 предложения будет достаточно. Добавьте бейджи для важных статусов проекта: статус разработки (в разработке, на поддержке и т.д.), статус билда, процент покрытия тестами и тд.

Содержание

//...
public function register()
{
$this->app->singleton('command.migrate.fresh', function () {
return new FreshCommand();
});
}
//...