Skip to content

Instantly share code, notes, and snippets.

View andreyvit's full-sized avatar

Andrey Tarantsov andreyvit

View GitHub Profile
@andreyvit
andreyvit / tmux.md
Created June 13, 2012 03:41
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

@andreyvit
andreyvit / remove-old-db-backups.sh
Created March 24, 2012 08:07
A script to remove old DB backup files, keeping one backup per month, one backup per day for the last X months and the last Y backups.
#! /bin/bash
# vim: sw=2 ts=2 et ai
NUM_OLDEST_BACKUPS_TO_KEEP=1
NUM_RECENT_BACKUPS_TO_KEEP=100
NUM_MONTHS_TO_KEEP_DAILY_BACKUPS=4
AUTOMATIC_REMOVAL_THRESHOLD=40
# Deletes old DB backup files from the folder specified as an argument.
#
@andreyvit
andreyvit / gist:2466992
Last active February 13, 2024 07:35
The Open Community Indie Software License
@andreyvit
andreyvit / UIPickerView_SelectionBarLabelSupport.h
Created October 23, 2009 01:08
UIPickerView category that allows to easily recreate the look and feel of UIDatePicker labeled components (HIG calls them “translucent bar labels”)
// UIPickerView_SelectionBarLabelSupport.h
//
// This file adds a new API to UIPickerView that allows to easily recreate
// the look and feel of UIDatePicker labeled components.
//
// Copyright (c) 2009, Andrey Tarantsov <andreyvit@gmail.com>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
@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 / fpdi_with_annots.php
Created March 12, 2012 07:16
FPDI extension to preserve external hyperlinks
<?php
// FPDI extension that preserves hyperlinks when copying PDF pages.
//
// (c) 2012, Andrey Tarantsov <andrey@tarantsov.com>, provided under the MIT license.
//
// Published at: https://gist.github.com/2020422
//
// Note: the free version of FPDI requires unprotected PDFs conforming to spec version 1.4.
// I use qpdf (http://qpdf.sourceforge.net/) to preprocess PDFs before running through this
@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;