Skip to content

Instantly share code, notes, and snippets.

@azechi
azechi / Decrypt_AuthenticationTicket.csproj
Last active October 3, 2018 19:47
.Net Core Decrypting Legacy FormsAuthenticationTicket (mode=Framework20SP2, SHA1, AES)
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<RootNamespace>App</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.3.0" />
@azechi
azechi / Clip_URLShortcut.bat
Created January 19, 2018 08:37
WindowsのSendToでWebページのショトートカットファイルを"[title url]"の文字にしてクリップボードに保存する
@fsi --exec %HOME%\bin\Clip_URLShortcut.fsx %* | clip
@pause
@azechi
azechi / LINQ_Method_QueryExp.csx
Last active June 22, 2018 03:17
Programming in Scala S23.2 The n-queens problem
Func<(int, int), (int, int), bool> inCheck = (q1, q2) => q1.Item1 == q2.Item1 || q1.Item2 == q2.Item2 || Math.Abs(q1.Item1 - q2.Item1) == Math.Abs(q1.Item2 - q2.Item2);
Func<(int, int), IEnumerable<(int, int)>, bool> isSafe = (queen, queens) => queens.All(q => !inCheck(queen, q));
Func<int, IEnumerable<IEnumerable<(int, int)>>> queens = n => {
Func<int, IEnumerable<IEnumerable<(int, int)>>> placeQueens = null;
placeQueens = k => {
if (k == 0){
return Enumerable.Repeat(Enumerable.Empty<(int, int)>(), 1);
} else {
@azechi
azechi / RandomBase32String.js
Last active July 3, 2023 17:14
Generate a random base32 string(length:6) using Web Crypto API
const base = "abcdefghijklmnopqrstuvwxyz234567" //a-z, 2-7
const array = new Int32Array(1)
window.crypto.getRandomValues(array)
const i = array[0]
var result =
base[i >>> 27 & 0x1f] +
base[i >>> 22 & 0x1f] +
base[i >>> 17 & 0x1f] +
@azechi
azechi / 0_read_QR_Code_from_webcam.html
Last active April 4, 2019 03:41
Read QR Code from video with web browser using cozmo/jsQR
<!DOCTYPE html>
<html>
<head>
<style>
#canvas {
width: 100%;
vertical-align: bottom;
}
body {
max-width: 640px;
@azechi
azechi / GetIPAddress.js
Last active April 24, 2019 01:38
Find out IP Address on the public side of a NAT using public stun server
function getIPAddress() {
const S = "stun.l.google.com:19302";
return new Promise(resolve=>{
const pc = new RTCPeerConnection({
"iceServers": [{
"urls": ["stun:" + S]
}]
@azechi
azechi / win32api_WindowRect.ipynb
Created December 3, 2019 00:47
windows api, QueryFullProcessImageName, DwmGetWindowAttribute,
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@azechi
azechi / Dockerfile
Created April 10, 2020 13:40
docker discordrb
FROM ruby AS builder
COPY Gemfile Gemfile.lock ./
RUN env DEBCONF_NOWARNINGS=yes bundle install -j "$(getconf _NPROCESSORS_ONLN)" --retry 3 \
&& rm -rf /usr/local/bundle/cache/*.gem \
&& find /usr/local/bundle/gems/ -name '*.c' -delete \
&& find /usr/local/bundle/gems/ -name '*.o' -delete
# app
FROM ruby:slim
RUN apt-get update \
@azechi
azechi / pkce.js
Created September 26, 2020 05:16
JavaScript RFC7636 PKCE code_verifier and SHA-256 code_challenge with Web Cryptography API
//https://tools.ietf.org/html/rfc7636#appendix-B
const code_verifier = btoa(
String.fromCharCode(...crypto.getRandomValues(new Uint8Array(32)))
).replace(/\/|\+|=/g, (x) => ({ "/": "_", "+": "-", "=": "" }[x]));
const hash = await crypto.subtle.digest(
"SHA-256",
new Uint8Array([...code_verifier].map((e) => e.charCodeAt(0)))
);
@azechi
azechi / client.js
Created January 24, 2021 01:48
discord.js, voice channel, streaming, raw PCM, child process
const BOT_TOKEN = process.env.DISCORD_BOT_TOKEN;
const CHANNEL_ID = process.env.VOICE_CHANNEL_ID;
const { spawn } = require('child_process');
const Discord = require('discord.js');
const prism = require('prism-media');
const client = new Discord.Client();
client.on('ready', async () => {