Skip to content

Instantly share code, notes, and snippets.

View Gurpartap's full-sized avatar
:octocat:
Working from home

Gurpartap Singh Gurpartap

:octocat:
Working from home
View GitHub Profile
@KaneCheshire
KaneCheshire / AnyTask.swift
Last active May 7, 2024 08:13
Type-erased Swift Task that cancels itself on deinit
/// A type-erased task that you can store in a collection
/// to allow you to cancel at a later date.
///
/// Upon deinit of the task, the task will be cancelled
/// automatically. Similar to Combine's AnyCancellable.
final class AnyTask {
/// Call this cancellation block to cancel the task manually.
let cancel: () -> Void
/// Checks whether the task is cancelled.
@moyix
moyix / killbutmakeitlooklikeanaccident.sh
Created February 5, 2022 22:51
Script to inject an exit(0) syscall into a running process. NB: only x86_64 for now!
#!/bin/bash
gdb -p "$1" -batch -ex 'set {short}$rip = 0x050f' -ex 'set $rax=231' -ex 'set $rdi=0' -ex 'cont'
@Tostino
Tostino / uuid_time_nextval.sql
Created January 22, 2021 20:09
PL/PGSQL Function for uuid_time_nextval
CREATE FUNCTION uuid_time_nextval(interval_length int default 60, interval_count int default 65536)
RETURNS uuid
LANGUAGE plpgsql
AS $$
DECLARE
v_i int;
v_prefix_bytes int = 0;
v_time bigint;
v_bytes int[16] = '{}';
v_hex text[16] = '{}';
@kquinsland
kquinsland / dummy0.netdev
Created December 3, 2019 02:54
How to get consul-agent and systemd.resolvd to co-exist peicefully and still be able to resolve *.consul hostsnames from within docker
# Creates a "dummy" network interface
# we'll configure this interface with a link-local address
# See: https://www.freedesktop.org/software/systemd/man/systemd.netdev.html
##
[NetDev]
Name=dummy0
Kind=dummy
@ZhipingYang
ZhipingYang / PopupPresentation.swift
Created November 15, 2019 03:22
UIViewControllerAnimatedTransitioning, UIPresentationController, UIViewControllerTransitioningDelegate
//
// ShareScreenPresentation.swift
// RoomsController
//
// Created by Daniel Yang on 2019/3/15.
// Copyright © 2019 RingCentral. All rights reserved.
//
import ObjectiveC
import UIKit
@jarrodldavis
jarrodldavis / RawKeyedCodableDictionary.swift
Created September 26, 2019 04:38
A Swift property wrapper for encoding and decoding `RawRepresentable` enums as their raw values in `Dictionary` instances as keys
@propertyWrapper
struct RawKeyedCodableDictionary<Key, Value>: Codable where Key: Hashable & RawRepresentable, Key.RawValue: Codable & Hashable, Value: Codable {
var wrappedValue: [Key: Value]
init() {
wrappedValue = [:]
}
init(wrappedValue: [Key: Value]) {
self.wrappedValue = wrappedValue
@sleepyfox
sleepyfox / 2019-07-25-users-hate-change.md
Last active December 10, 2023 18:20
'Users hate change'

'Users hate change'

This week NN Group released a video by Jakob Nielsen in which he attempts to help designers deal with the problem of customers being resistant to their new site/product redesign. The argument goes thusly:

  1. Humans naturally resist change
  2. Your change is for the better
  3. Customers should just get used to it and stop complaining

There's slightly more to it than that, he caveats his argument with requiring you to have of course followed their best practices on product design, and allows for a period of customers being able to elect to continue to use the old site, although he says this is obviously only a temporary solution as you don't want to support both.

@nakov
nakov / AES-256-CTR-Argon2-HMAC-SHA256-example.js
Last active November 9, 2023 02:32
Cryptography for JavaScript Developers: Hashes, HMAC, PBKDF2, Scrypt, Argon2, AES-256-CTR, ECDSA, EdDSA, secp256k1, Ed25519
const aes = require("aes-js");
const argon2 = require("argon2");
const crypto = require("crypto");
const cryptoJS = require("crypto-js");
// Encrypt using AES-256-CTR-Argon2-HMAC-SHA-256
async function aes256ctrEncrypt(plaintext, password) {
let argon2salt = crypto.randomBytes(16); // 128-bit salt for argon2
let argon2Settings = { type: argon2.argon2di, raw: true,
timeCost: 8, memoryCost: 2 ** 15, parallelism: 2,
@GeorgeLyon
GeorgeLyon / Rust vs. Swift.md
Last active April 4, 2024 21:16
A list of advantages Swift has over Rust

Note This is a little out of date. Rust has made some progress on some points, however many points still apply.

Philosophy

Progressive disclosure

Swift shares Rust's enthusiasm for zero-cost abstractions, but also emphasizes progressive disclosure. Progressive disclosure requires that language features should be added in a way that doesn't complicate the rest of the language. This means that Swift aims to be simple for simple tasks, and only as complex as needed for complex tasks.

The compiler works for you

gif-from-tweet

There are so many great GIFs out there and I want to have copies of them. Twitter makes that harder than it should be by converting them to MP4 and not providing access to the source material. To make it easier, I made a bash pipeline that takes a tweet URL and a filename, extracts the MP4 from that tweet and uses ffmpeg to convert back to GIF.

Dependencies

  • ffmpeg
    • macOS: brew install ffmpeg
    • Ubuntu/Debian: apt install ffmpeg