Skip to content

Instantly share code, notes, and snippets.

@myd7349
myd7349 / repo-rinse.sh
Created January 22, 2022 02:38 — forked from nicktoumpelis/repo-rinse.sh
Cleans and resets a git repo and its submodules
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
@myd7349
myd7349 / TwoMethods.md
Created February 7, 2022 05:40 — forked from bloc97/TwoMethods.md
Two Fast Methods of Generating True Random Numbers on the Arduino

Two Fast Methods of Generating True Random Numbers on the Arduino

Arduino true random number generator

B. Peng

December 2017

Abstract

The AVR series microcontrollers are a collection of cheap and versatile chips that are used in many applications ranging from hobbist projects to commercial infrastructure. One major problem for some hobbists is the lack of secure random number generation on the Arduino platform. The included pseudo-random number generator (PRNG) is very easy to defeat and is useless for any crypto-related uses. One recommendation from the Arduino Reference Manual is to use atmospheric noise from the chip's analog sensor pins as seed data[6].
Unfortunately this method is extremely weak and should not be used to emulate a true random number generator (TRNG). Existing methods such as using the internal timer drift or using a dedicated generator are either too slow, requires extensive external hardware or modifications to the microcontroller's internal mech

@myd7349
myd7349 / kpc_demo.c
Created May 10, 2022 05:49 — forked from ibireme/kpc_demo.c
A demo shows how to read Intel or Apple M1 CPU performance counter in macOS.
// =============================================================================
// XNU kperf/kpc demo
// Available for 64-bit Intel/Apple Silicon, macOS/iOS, with root privileges
//
//
// Demo 1 (profile a function in current thread):
// 1. Open directory '/usr/share/kpep/', find your CPU PMC database.
// For M1 (Pro/Max), the database file is '/usr/share/kpep/a14.plist'.
// 2. Select a few events that you are interested in,
// add their names to the `profile_events` array below.
@myd7349
myd7349 / Interpolator.cs
Created May 24, 2022 08:07 — forked from dreikanter/Interpolator.cs
Spline interpolation in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace Interpolation
{
/// <summary>
/// Spline interpolation class.
@myd7349
myd7349 / weread.user.js
Created June 15, 2022 16:36 — forked from jianyun8023/weread.user.js
weread download,生成kindlegen可用的源文件,可用来生成mobi
// ==UserScript==
// @name 微信读书下载
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 下载微信读书的书籍资源
// @author You
// @match https://weread.qq.com/web/reader/*
// @grant unsafeWindow
// @grant GM_setValue
// @grant GM_getValue
@myd7349
myd7349 / capture.py
Created July 9, 2022 06:16 — forked from oinume/capture.py
Capture stdout/stderr in Python
import cStringIO
import sys
class IOCapture(object):
def __init__(self, stdout = True, stderr = True):
self.captured_stdout = None
self.captured_stderr = None
if stdout:
self.captured_stdout = cStringIO.StringIO()
if stderr:
@myd7349
myd7349 / object_layout.cc
Created July 13, 2022 05:14 — forked from gnarayan81/object_layout.cc
Viewing object layout in clang.
// The intent of this class is to display the layout of an object in
// memory.
// Compile with:
// clang -cc1 -x c++ -v -fdump-record-layouts test.cc -emit-llvm -o /dev/null
//
//
//*** Dumping AST Record Layout
//0 | struct Top
//0 | int a
//| [sizeof=4, dsize=4, align=4
@myd7349
myd7349 / Makefile
Created July 13, 2022 05:54 — forked from GavinRay97/Makefile
Dump C/C++ vtable & record layout information (clang + msvc + gcc)
# Requirements:
# clang - The classes/structs you want to dump must be used in code at least once, not just defined.
# MSVC - The classes/structs you want to dump must have "MEOW" in the name for "reportSingleClass" to work.
# Usage:
# $ make dump_vtables file=test.cpp
dump_vtables:
clang -cc1 -fdump-record-layouts -emit-llvm $(file) > clang-vtable-layout-$(file).txt
clang -cc1 -fdump-vtable-layouts -emit-llvm $(file) > clang-record-layout-$(file).txt
g++ -fdump-lang-class=$(file).txt $(file)
cl.exe $(file) /d1reportSingleClassLayoutMEOW > msvc-single-class-vtable-layout-$(file).txt
@myd7349
myd7349 / MSVC_AST_GEN.cmd
Created July 13, 2022 07:48 — forked from K2/MSVC_AST_GEN.cmd
MSVC AST generation
REM AST generation from MSVC
cl /analyze /d1Aprintast %1 > %1.ast
@myd7349
myd7349 / ButtonStackPanel.xaml
Created July 27, 2022 09:33 — forked from markheath/ButtonStackPanel.xaml
Example WPF Button Template
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<Style x:Key="MyFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Control}">
<Grid Margin="3 2">