Skip to content

Instantly share code, notes, and snippets.

@simulacra-mechatronics
simulacra-mechatronics / main.cpp
Last active May 15, 2024 12:30
Win32 C++ non-rectangular window skin and non-rectangular button skin using SetLayeredWindowAttributes() and SetWindowRgn()
#include <windows.h>
#include <iostream> // Used for outputting info via 'cout' or 'cerr' to debug window
#include "resource.h" // Contains declarations of resources contained in resource file
void DestroyCaption(HWND hwnd, int windowWidth, int windowHeight); // Used to remove window caption and size window to bitmap size
HRGN CreateRgnFromFile(HBITMAP hBmp, COLORREF color); // Function that accepts a bitmap with color keyed to transparency and defines a region according to non transparent area
typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags); // Get a function pointer
lpfnSetLayeredWindowAttributes SetLayeredWindowAttributes; // Set instance of function pointer
@TheCherno
TheCherno / Instrumentor.h
Last active July 20, 2024 13:55
Basic Instrumentation Profiler
//
// Basic instrumentation profiler by Cherno
// Usage: include this header file somewhere in your code (eg. precompiled header), and then use like:
//
// Instrumentor::Get().BeginSession("Session Name"); // Begin session
// {
// InstrumentationTimer timer("Profiled Scope Name"); // Place code like this in scopes you'd like to include in profiling
// // Code
// }
@dchest
dchest / chrome.md
Last active April 2, 2024 20:15
How to properly use Chrome
  1. Install uBlock Origin extension. (If you're not from US, check its options to turn on ad block lists for your country)

  2. Do not install any other extensions ever! (exceptions: 1Password, Google Arts & Culture).

  3. Create separate "people" for different activities: e.g. home, work, browsing sketchy websites. (Click on avatar > Manage People)

  4. If you want to turn on sync, set up encryption passphrase. It's a separate passphrase from your Google account — your sync data will be encrypted locally with it before hitting Google servers.

  5. Disable saving/auto fill of passwords, payment, and addresses. (https://twitter.com/Sc00bzT/status/1085521985017466881)

@tunabrain
tunabrain / Range.hpp
Last active August 1, 2019 08:30
Python ranges in C++
#ifndef RANGE_HPP_
#define RANGE_HPP_
template<typename T> class RangeIterator;
template<typename T>
class Range
{
T _start, _end, _step;
@antirez
antirez / lmdb.tcl
Created April 28, 2017 15:40
LMDB -- First version of Redis written in Tcl
# LVDB - LLOOGG Memory DB
# Copyriht (C) 2009 Salvatore Sanfilippo <antirez@gmail.com>
# All Rights Reserved
# TODO
# - cron with cleanup of timedout clients, automatic dump
# - the dump should use array startsearch to write it line by line
# and may just use gets to read element by element and load the whole state.
# - 'help','stopserver','saveandstopserver','save','load','reset','keys' commands.
# - ttl with milliseconds resolution 'ttl a 1000'. Check ttl in dump!

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.

Listpack specification

Version 1.0, 1 Feb 2017: Intial specification.

Version 1.1, 2 Feb 2017: Integer encoding simplified. Appendix A added.

Version 1.2, 3 Feb 2017: Better specify the meaning of the num-elements
                         field with value of 65535. The two 12 bits

positive/negative integers encodings were

@takikoo
takikoo / README.md
Last active February 26, 2024 07:10
Export bookmarks from Google Chrome with a batch script

Export chrome bookmarks

This is a script to export bookmarks from the web browser Google Chrome to a users home drive in a Windows environment with clients and domain controllers. Most of the script comes from this article

Instruction

  • Double-click on the bat-file.
  • Go the home drive on the users new computer.
  • Double-click on openChromeFolder.bat which will take you to the chrome directory on that machiene.
  • Copy the file Bookmarks to the newly opened window.
@balpha
balpha / Program.cs
Created May 4, 2016 12:46
Job title and company name generator
using System;
using System.Linq;
namespace FakeJobInfo
{
class Program
{
private static Func<int, int> rand = new Random().Next;