Skip to content

Instantly share code, notes, and snippets.

@juj
juj / raspberry_pi_zero_linear_diff.cpp
Created July 5, 2018 18:31
Raspberry Pi Zero linear memory block diff
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <syslog.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <stdint.h>
@juj
juj / raspberry_pi_zero_linear_diff_v2.cpp
Created July 8, 2018 21:03
Raspberry Pi Zero linear memory block diff version 2
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <syslog.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <stdint.h>
@juj
juj / command_line.bat
Created February 26, 2019 13:43
Install Emscripten
::Install
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
emsdk install sdk-incoming-64bit
emsdk activate sdk-incoming-64bit
emsdk_env.bat
::Build
cd emscripten\incoming
em++ tests/hello_world.cpp -o hello_world.js
@juj
juj / command_line.sh
Created February 26, 2019 13:38
Install Emscripten
# Install:
cd ~
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install sdk-incoming-64bit
./emsdk activate sdk-incoming-64bit
source ./emsdk_env.sh
# Build:
cd emscripten/incoming
@juj
juj / gowin_verilog_dcs_and_rpll.v
Created November 2, 2022 19:07
How to use Gowin's DCS (Dynamic Clock Select) and rPLL module instances and properly configure timing analysis
module top(
input clk_27mhz, // The built-in 27 MHz oscillator clock. Using timing constraint: create_clock -name clk_27mhz -period 37.037 [get_ports {clk_27mhz}]
input external_clk, // And external clock signal at 12.5 - 32 MHz frequency. Using timing constraint: create_clock -name external_clk -period 31.25 [get_ports {external_clk}]
input which_clock_to_use,
output reg o_a,
output reg o_b,
output o_clk
);
always @(posedge clk_27mhz) begin
@juj
juj / code.cs
Created November 10, 2022 10:15
Unity JS -> C# new array allocation marshalling
using System;
using System.Runtime.InteropServices;
using UnityEngine;
public class code : MonoBehaviour
{
void Start()
{
Method1();
Method2();
@juj
juj / 3B.cpp
Created December 4, 2022 17:28
Advent of Code Day 3, problem B.
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
char *read_file_to_string(const char *filename)
{
FILE *handle = fopen(filename, "r");
fseek(handle, 0, SEEK_END);
long size = ftell(handle);
fseek(handle, 0, SEEK_SET);
@juj
juj / 6.cpp
Last active December 6, 2022 11:04
Advent of Code 2022, Day 6
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
char *read_file_to_string(const char *filename)
{
FILE *handle = fopen(filename, "r");
fseek(handle, 0, SEEK_END);
long size = ftell(handle);
fseek(handle, 0, SEEK_SET);
@juj
juj / cube_folding.py
Last active January 9, 2023 22:26
Advent of Code 2022 Day 22 Cube folding solver
# Usage: python cube_folding.py input.txt
import math, sys
lines = open(sys.argv[1] if len(sys.argv) > 1 else 'input.txt', 'r').read().split('\n')
# Remove instructions line from input
lines = lines[:-1]
if len(lines[-1]) == 0: lines.pop() # Remove possible empty line between map and instructions
# Compute cube surface area
@juj
juj / 60hz.cpp
Created January 11, 2023 20:54
How to reprogram VGA registers to a 320x200@60hz mode with either square pixels or 5:6 pixels.
// License: public domain.
#include <dos.h>
#include <conio.h>
void set_video_mode(int mode)
{
union REGS regs;
regs.x.ax = mode;
int86(0x10, &regs, &regs);