Skip to content

Instantly share code, notes, and snippets.

View lancejpollard's full-sized avatar
🐢
Code

Lance Pollard lancejpollard

🐢
Code
View GitHub Profile
@lancejpollard
lancejpollard / malloc.c
Created December 10, 2019 09:02 — forked from mshr-h/malloc.c
simple malloc implementation
/* Include the sbrk function */
#include <unistd.h>
int has_initialized = 0;
void *managed_memory_start;
void *last_valid_address;
void malloc_init() { /* grab the last valid address from the OS*/
last_valid_address = sbrk(0);
/* we don't have any memory to manage yet, so
@lancejpollard
lancejpollard / client.c
Created April 5, 2020 02:43 — forked from suyash/client.c
TCP echo client-server in C
#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
int main() {
const char* server_name = "localhost";
const int server_port = 8877;
@lancejpollard
lancejpollard / chacha20.js
Created May 29, 2020 10:50 — forked from rumkin/chacha20.js
Chacha20-Poly1305.js
/* chacha20 - 256 bits */
// Written in 2014 by Devi Mandiri. Public domain.
//
// Implementation derived from chacha-ref.c version 20080118
// See for details: http://cr.yp.to/chacha/chacha-20080128.pdf
function U8TO32_LE(x, i) {
return x[i] | (x[i+1]<<8) | (x[i+2]<<16) | (x[i+3]<<24);
}
page ,132
title memcpy - Copy source memory bytes to destination
;***
;memcpy.asm - contains memcpy and memmove routines
;
; Copyright (c) Microsoft Corporation. All rights reserved.
;
;Purpose:
; memcpy() copies a source memory buffer to a destination buffer.
; Overlapping buffers are not treated specially, so propogation may occur.
@lancejpollard
lancejpollard / binary-addition.js
Created July 6, 2020 02:40 — forked from nealfennimore/binary-addition.js
Binary addition in javascript
/**
* Add two bits together and get resulting bits
*
* @param {Number} a bit a
* @param {Number} b bit b
* @returns {Array<Number, Number>} Carry and sum as a result of addition
*/
function addBits(a, b){
return [ +( a && b ), +( a !== b ) ];
@lancejpollard
lancejpollard / dnsmasq_setup_osx.md
Created July 26, 2020 18:16 — forked from eloypnd/dnsmasq_setup_osx.md
wildcard DNS record on OS X in localhost development with dnsmasq

wildcard DNS in localhost development

$ brew install dnsmasq
   ...
$ cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
  • edit /usr/local/etc/dnsmasq.conf
address=/local/127.0.0.1
@lancejpollard
lancejpollard / btree.js
Created January 3, 2021 21:27 — forked from felipecrv/btree.js
In-memory B+ Tree implemented in Javascript with Flow type annotations
/* @flow */
const KEY_KIND_STRING = 1;
const KEY_KIND_NUMBER = 2;
const KEY_KIND_BOOL = 3;
const KEY_KIND_RECORD = 4;
type KeyKind = 1 | 2 | 3 | 4;
class KeyValue<K, V> {
key: ?K;
@lancejpollard
lancejpollard / syscalls.json
Created January 27, 2021 14:06 — forked from jasonwhite/syscalls.json
x64 syscalls
[
{
"num": 0,
"name": "sys_read",
"params": [
[
"unsigned int",
"fd"
],
[
@lancejpollard
lancejpollard / x86-assembly-notes.md
Created January 27, 2021 22:45 — forked from mikesmullin/x86-assembly-notes.md
Notes on x86-64 Assembly and Machine Code

Mike's x86-64 Assembly (ASM) Notes

Assembling Binary Machine Code

Operating Modes:

These determine the assumed/default size of instruction operands, and restricts which opcodes are available, and how they are used.

Modern operating systems, booted inside Real mode,