Skip to content

Instantly share code, notes, and snippets.

@FeepingCreature
FeepingCreature / youre_doing_json_apis_wrong.md
Last active March 14, 2025 09:16
You Are Doing JSON APIs Wrong

You are doing JSON APIs wrong.

When you use JSON to call an API - not a REST API, but something like JSON-RPC - you will usually want to encode one of several possible messages.

Your request body looks like this:

{
 "type": "MessageWithA",
@frabert
frabert / COPYING
Last active December 21, 2023 13:35
Favicons for HN
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
@Henje
Henje / papers_please_fix.cpp
Last active February 28, 2023 23:10
Simple hack to disable joystick scanning and remove stutters from Papers Please.
#include <string>
#include <dlfcn.h>
#include <stdio.h>
#include <sys/mman.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
using namespace std::literals;
@dominictarr
dominictarr / readme.md
Created November 26, 2018 22:39
statement on event-stream compromise

Hey everyone - this is not just a one off thing, there are likely to be many other modules in your dependency trees that are now a burden to their authors. I didn't create this code for altruistic motivations, I created it for fun. I was learning, and learning is fun. I gave it away because it was easy to do so, and because sharing helps learning too. I think most of the small modules on npm were created for reasons like this. However, that was a long time ago. I've since moved on from this module and moved on from that thing too and in the process of moving on from that as well. I've written way better modules than this, the internet just hasn't fully caught up.

@broros

otherwise why would he hand over a popular package to a stranger?

If it's not fun anymore, you get literally nothing from maintaining a popular package.

One time, I was working as a dishwasher in a restu

@al3rez
al3rez / main.cr
Created December 13, 2017 19:00
Building a RESTful API with Crystal
require "http/server"
class Users::Me
include HTTP::Handler
def call(context)
return call_next(context) unless match?(context.request)
STDOUT.puts "getting user info..."
STDOUT.puts "done!"
@marwei
marwei / how_to_reset_kafka_consumer_group_offset.md
Created November 9, 2017 23:39
How to Reset Kafka Consumer Group Offset

Kafka 0.11.0.0 (Confluent 3.3.0) added support to manipulate offsets for a consumer group via cli kafka-consumer-groups command.

  1. List the topics to which the group is subscribed
kafka-consumer-groups --bootstrap-server <kafkahost:port> --group <group_id> --describe

Note the values under "CURRENT-OFFSET" and "LOG-END-OFFSET". "CURRENT-OFFSET" is the offset where this consumer group is currently at in each of the partitions.

  1. Reset the consumer offset for a topic (preview)
#!/bin/sh
# to run this, use the following:
# curl https://matthewbauer.us/kernel-panic.sh | sh
cfile=$(mktemp).c
cat <<EOF >> $cfile
#include <unistd.h>
#include <sys/syscall.h>
#include <signal.h>
@C-Duv
C-Duv / 0.Notes.md
Created August 1, 2017 23:31
Example for Docker Swarm, Let's Encrypt and Nginx setup with no Nginx down time (answer to https://twitter.com/developius/status/892470102632923136)
@huyinghuan
huyinghuan / encrypt_file_pkcs5_pkcs7.go
Created May 31, 2017 07:44
golang encrypt with pkcs5 and pkcs7
package main
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"errors"
"io"
"io/ioutil"
@analogist
analogist / gce_md5convert.sh
Last active April 26, 2022 06:45
Convert Google Cloud Storage gsutil ls -L base64-encoded md5 hash listings to md5sum-compatible hash format
#!/bin/bash
# This awk/sed script looks for "gs://bucket/path/filename" and "Hash (md5)",
# swaps the two (so the hash appears before the file, in the md5sum format),
# cuts out the "gs://bucket/" name, and finally converts the md5 hash
# from base64 to hex. This allows for later off-line file integrity check
# via the standard "md5sum -c".
#
# To use it, either save it as an alias or a shell script, and pipe the
# output of gsutil ls -L through it. For example, save it as "md5convert.sh"
# and then run "gsutil ls -L gs://bucket/path | bash md5convert.sh"