Skip to content

Instantly share code, notes, and snippets.

View andreyvit's full-sized avatar

Andrey Tarantsov andreyvit

View GitHub Profile
@andreyvit
andreyvit / jwt.go
Created September 14, 2023 13:43
Example simple JWT implementation for Go
package jwt
import (
"bytes"
"crypto/hmac"
"crypto/sha256"
"crypto/subtle"
"encoding/base64"
"encoding/json"
"errors"
package accesstokens
import (
"crypto/hmac"
"crypto/sha256"
"crypto/subtle"
"encoding/hex"
"errors"
"strings"
"time"
@andreyvit
andreyvit / chatgpt-puppeteer.js
Last active March 3, 2023 07:08
ChatGPT Chromium driver from before OpenAI released ChatGPT API
let puppeteer = require('puppeteer-core') // tested with puppeteer-core 19.7.1
let fs = require('fs')
let BROWSER_ENDPOINT = process.env.BROWSER_ENDPOINT
if (!BROWSER_ENDPOINT) {
console.error("** BROWSER_ENDPOINT not set (expect smt like ws://127.0.0.1:9222/devtools/browser/aaaaaaaa-bbbb-cccc-dddd-ffffffffffff)\n\n" +
"To obtain, launch your favorite Chromium-based browser with --remote-debugging-port=9222\n" +
"and look at the output. E.g.:\n\n" +
" '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge' --remote-debugging-port=9222\n\n" +
"and it's gonna say:\n\n" +
@andreyvit
andreyvit / extractiraw.go
Created June 18, 2020 10:51
Extract .iraw files that some Flash videoconferencing systems use
package main
import (
"log"
"os"
"io/ioutil"
"encoding/binary"
"net/http"
"mime"
"fmt"
@andreyvit
andreyvit / ATRichCheckbox.h
Created June 10, 2020 10:59
UIKit checkbox control that supports embedded links (for ToS acceptance checkbox)
@import UIKit;
typedef void (^RDLCheckboxURLHandler)(NSURL *url);
IB_DESIGNABLE
@interface ATRichTextCheckbox : UIControl
@property (nonatomic, readonly) UIButton *checkbox;
@andreyvit
andreyvit / filter-windbg-address-map.go
Created December 5, 2018 13:08
A script to filter and summarise the memory map produced by `!address` command in WinDbg (requires Go 1.11)
package main
import (
"bytes"
"flag"
"io/ioutil"
"log"
"strconv"
"strings"

Memory Leak Report

Many web apps leak memory on IE11 despite running fine on other browsers. We've identified two main causes of this.

The first kind of leak is simple, entirely predictable and caused by a quirk in how IE's JavaScript engine handles closures. Let's call it an “undead closure leak”. This leak goes away if you properly clean up all references or reload the page, and thus affects only AJAXy parts of the apps.

The second kind of leak is a complex permanent one, leaking the entire page context even if you reload the page. Let's call it a “GC singularity leak”. It's triggered by certain JavaScript code patterns, seemingly because IE's garbage collector never finishes its job (our theory is that it exhibits exponential complexity and encounters some sort of timeout/threshold).

This might not be an exhaustive list; internet posts point to other issues, notably when handling IFRAMEs, but we haven't encountered any of these.

@andreyvit
andreyvit / ie11leak.html
Created November 20, 2018 11:58
A minimal reproduction case for a weird IE11 memory leak
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script crossorigin src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script>
(function () {
var doc = document;
@andreyvit
andreyvit / Как редактировать подкаст.md
Last active May 1, 2018 11:36
Как редактировать подкаст

Как редактировать подкаст

На входе

Файлы от каждого участника подкаста (FLAC / AAC). По сути моно. У некоторых два канала с микрофона. У некоторых в левом канале микрофон (это то, что нас интересует), а в правом то, что они слышали (это нужно использовать для выравнивания звуковых дорожек, а потом выбросить). Моменты начала (и окончания) записи на файлах не синхронизированы.

Что нужно сделать

  1. Добавить файлы в многотрековый проект Adobe Audition.
  2. Совместить файлы так, чтобы разговор на разных дорожках совпадал.
@andreyvit
andreyvit / MYPROJPromise.h
Created December 25, 2017 10:45
My template for server operations with using AFNetworking or any other 3rd-party code (in Objective-C)
@import Foundation;
typedef void (^MYPROJPromiseResultBlock)(id result);
typedef void (^MYPROJPromiseErrorBlock)(NSError *error);
typedef void (^MYPROJPromiseResultAndErrorBlock)(id result, NSError *error);
typedef void (^MYPROJPromiseErrorAndResultBlock)(NSError *error, id result);
typedef void (^MYPROJPromiseResultOrErrorBlock)(id resultOrError);
typedef void (^MYPROJPromiseWorkBlock)(MYPROJPromiseResultAndErrorBlock completionHandler);