Skip to content

Instantly share code, notes, and snippets.

View bullno1's full-sized avatar
💭
Set your status

Bach Le bullno1

💭
Set your status
View GitHub Profile
@RandyGaul
RandyGaul / edge_interesections.cpp
Last active November 15, 2022 15:18
Calculate edge-edge intersections of convex polygons via Sutherland-Hodgman in 2D
#ifndef _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_WARNINGS
#endif
#ifndef _CRT_NONSTDC_NO_DEPRECATE
# define _CRT_NONSTDC_NO_DEPRECATE
#endif
#include <vector>
// -------------------------------------------------------------------------------------------------
@nickav
nickav / ReadDirectoryChangesW_craziness.cpp
Last active February 26, 2024 10:02
Example of how to poll ReadDirectoryChangesW on Windows
int main() {
char *path = "/path/to/my/directory";
print("watching %s for changes...\n", path);
HANDLE file = CreateFile(path,
FILE_LIST_DIRECTORY,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED,
@maxlapshin
maxlapshin / systemd.erl
Last active December 24, 2022 17:28
Systemd support
-module(systemd).
% This is what you need to adopt systemd in erlang
%
% Do whatever you want license. If you want, you can take this code under terms of MIT license.
-export([ready/0, reloading/0, stopping/0, watchdog/0]).
-export([start_link/0]).
-export([init/1, handle_info/2, terminate/2]).
@jspohr
jspohr / microsecs.c
Last active March 9, 2024 13:32
Avoid overflow when converting time to microseconds
// Taken from the Rust code base: https://github.com/rust-lang/rust/blob/3809bbf47c8557bd149b3e52ceb47434ca8378d5/src/libstd/sys_common/mod.rs#L124
// Computes (value*numer)/denom without overflow, as long as both
// (numer*denom) and the overall result fit into i64 (which is the case
// for our time conversions).
int64_t int64MulDiv(int64_t value, int64_t numer, int64_t denom) {
int64_t q = value / denom;
int64_t r = value % denom;
// Decompose value as (value/denom*denom + value%denom),
// substitute into (value*numer)/denom and simplify.
// r < denom, so (denom*numer) is the upper bound of (r*numer)
Originally from: http://erlang.org/pipermail/erlang-questions/2017-August/093170.html
For a safe and fast Erlang SSL server, there's a few
configuration values you might want by default:
[{ciphers, CipherList}, % see below
{honor_cipher_order, true}, % pick the server-defined order of ciphers
{secure_renegotiate, true}, % prevent renegotiation hijacks
{client_renegotiation, false}, % prevent clients DoSing w/ renegs
{versions, ['tlsv1.2', 'tlsv1.1']}, % add tlsv1 if you must
@niklas-ourmachinery
niklas-ourmachinery / identifying-controls-in-an-imgui.md
Last active January 24, 2023 06:09
Identifying controls in an IMGUI

Identifying controls in an IMGUI

In an IMGUI we need a way to identify which control is active or hot. For example, when we press a key, which text box does the text go to.

Possible options:

  1. Sequential number (Unity)

Each control drawn gets a sequentially increasing number.

@TechFounder
TechFounder / style.css
Created June 27, 2016 03:05
Buddha bless your code to be bug free
//
// _oo0oo_
// o8888888o
// 88" . "88
// (| -_- |)
// 0\ = /0
// ___/`---'\___
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- |||||- \
@makeev
makeev / create_pkcs7_sign.py
Created March 28, 2016 13:25
Creating a PKCS #7 detached signature of the manifest file for safari push package in python
import M2Crypto
def main():
manifest_path = 'path/to/manifest.json'
signature_path = 'path/to/signature'
# to convert .cer to .pem
# openssl x509 -inform der -in certificate.cer -out certificate.pem
# to combine certificate and key
# cat PushChatCert.pem PushChatKey.pem > ck.pem
@bellbind
bellbind / cpuinfo.c
Created October 29, 2015 07:07
[c][intel][clang] get cpu info from CPUID intrinsic in clang/gcc
// intel CPUID opcode
// see: https://en.wikipedia.org/wiki/CPUID
// clang -Wall -Wextra -std=c11 cpuinfo.c -o cpuinfo
#include <stdint.h>
#include <stdio.h>
#include <cpuid.h> //macro __cpuid(eaxin, eaxout, ebx, ecx, edx)
int main() {
{
function construct(constructor, args) {
function F() {
return constructor.apply(this, args);
}
F.prototype = constructor.prototype;
return new F();
}
// Sanboxer
function sandboxcode(string, inject) {
"use strict";