Skip to content

Instantly share code, notes, and snippets.

@minhphuc429
minhphuc429 / hash.mqh
Created March 28, 2020 22:24
Libraries: JSON Parser MQL4
// $Id: hash.mqh 125 2014-03-03 08:38:32Z ydrol $
#ifndef YDROL_HASH_MQH
#define YDROL_HASH_MQH
//#property strict
/*
This is losely ported from a C version I have which was in turn modified from hashtable.c by Christopher Clark.
Copyright (C) 2014, Andrew Lord (NICKNAME=lordy) <forex@NICKNAME.org.uk>
Copyright (C) 2002, 2004 Christopher Clark <firstname.lastname@cl.cam.ac.uk>
@simonw
simonw / recover_source_code.md
Last active May 17, 2024 18:28
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
@0xdevalias
0xdevalias / converting-json-to-openapi-swagger-spec.md
Created June 2, 2023 01:09
Exploring tools that allow converting a JSON response automagically into an OpenAPI / Swagger spec.

Converting JSON to OpenAPI / Swagger spec

Exploring tools that allow converting a JSON response automagically into an OpenAPI / Swagger spec.

Test JSON Response

{
    "accounts": {
        "default": {
@leommoore
leommoore / file_magic_numbers.md
Last active May 17, 2024 18:26
File Magic Numbers

File Magic Numbers

Magic numbers are the first bits of a file which uniquely identify the type of file. This makes programming easier because complicated file structures need not be searched in order to identify the file type.

For example, a jpeg file starts with ffd8 ffe0 0010 4a46 4946 0001 0101 0047 ......JFIF.....G ffd8 shows that it's a JPEG file, and ffe0 identify a JFIF type structure. There is an ascii encoding of "JFIF" which comes after a length code, but that is not necessary in order to identify the file. The first 4 bytes do that uniquely.

This gives an ongoing list of file-type magic numbers.

Image Files

@bkanhu
bkanhu / beginners_ubuntu.md
Last active May 17, 2024 18:26
A Beginners Guide on Things To Do After Installing Ubuntu.

Beginners Ubuntu

A Beginners Guide To Things To Do After Installing Ubuntu.

1. Check For Updates

sudo apt update && sudo apt upgrade

2. Enable additional repositories for more software

Ubuntu has several repositories from where it provides software for your system. Enabling all these repositories will give you access to more software and proprietary drivers.

@sjvnnings
sjvnnings / better_jumping_character_example.gd
Last active May 17, 2024 18:24
An easy to work with jump in Godot
extends KinematicBody2D
export var move_speed = 200.0
var velocity := Vector2.ZERO
export var jump_height : float
export var jump_time_to_peak : float
export var jump_time_to_descent : float
@samsch
samsch / stop-using-jwts.md
Last active May 17, 2024 18:24
Stop using JWTs

Stop using JWTs!

TLDR: JWTs should not be used for keeping your user logged in. They are not designed for this purpose, they are not secure, and there is a much better tool which is designed for it: regular cookie sessions.

If you've got a bit of time to watch a presentation on it, I highly recommend this talk: https://www.youtube.com/watch?v=pYeekwv3vC4 (Note that other topics are largely skimmed over, such as CSRF protection. You should learn about other topics from other sources. Also note that "valid" usecases for JWTs at the end of the video can also be easily handled by other, better, and more secure tools. Specifically, PASETO.)

A related topic: Don't use localStorage (or sessionStorage) for authentication credentials, including JWT tokens: https://www.rdegges.com/2018/please-stop-using-local-storage/

The reason to avoid JWTs comes down to a couple different points:

  • The JWT specification is specifically designed only for very short-live tokens (~5 minute or less). Sessions

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

// ==UserScript==
// @name Photopea Premium
// @namespace http://tampermonkey.net/
// @version 2024-02-03
// @description Unlock Photopea Premium by patching their JS
// @author mat
// @match https://www.photopea.com/
// @match https://www.photopea.com/?utm_source=homescreen
// @icon https://www.google.com/s2/favicons?sz=64&domain=photopea.com
// @grant GM_webRequest