Skip to content

Instantly share code, notes, and snippets.

@thevar1able
thevar1able / chip-8.rs
Created January 22, 2023 10:19
CHIP-8 emulator
use std::time::Duration;
use std::{env, io, fs, fmt};
use sdl2::Sdl;
use sdl2::pixels::Color;
use sdl2::render::Canvas;
struct Instruction {
bytes: [u8; 2],
}
@thevar1able
thevar1able / assembler.py
Created January 7, 2023 16:33
nand2tetris: HACK assembler
#!/usr/bin/env python3
import sys
def check_args():
if len(sys.argv) != 2:
print("Usage: python3 assembler.py <file.asm>")
sys.exit(1)
~ ❱ cat .bin/open-iterm2
#!/usr/bin/env bash
# Detects if iTerm2 is running
if ! pgrep -f "iTerm" > /dev/null; then
open -a "/Applications/iTerm.app"
else
# Create a new window
if ! osascript -e 'tell application "iTerm2" to create window with default profile' > /dev/null; then
# Get pids for any app with "iTerm" and kill
@thevar1able
thevar1able / main.py
Created October 5, 2022 03:39
2ch webm scraper
import os
import sqlite3
import requests
from collections import defaultdict
def create_schema():
conn = sqlite3.connect('db.sqlite')
c = conn.cursor()
c.execute('''CREATE TABLE posts
"""
1. Create a list of first names
2. Create a list of last names
3. Combine them randomly into a list of 100 full names
4. Insert into sqlite table "Names"
"""
import sqlite3
import random

lenta.com basic promotions API

  • Get your store id at https://lenta.com/api/v1/stores/
  • Grab promoted goods info at:
    https://lenta.com/api/v1/stores/<store_id>/home
    https://lenta.com/api/v1/stores/<store_id>/crazypromotions
    https://lenta.com/api/v1/stores/<store_id>/mobilepromo?hideAlcohol=false&limit=15&offset=0&type=weekly
    

on Pi:

ffmpeg -f v4l2 -input_format mjpeg -video_size 1280x720 -framerate 60 -i /dev/video0 -c:v h264_omx -framerate 60 -b:v 1k -flags:v +global_header -bsf:v dump_extra -f rawvideo udp://phi:25000

on client:

vlc --demux h264 udp://@:25000
package hw06_pipeline_execution //nolint:golint,stylecheck
type (
I = interface{}
In = <-chan I
Out = In
Bi = chan I
)
type Stage func(in In) (out Out)
#!/usr/bin/env python3
import time
import logging
from pydbus import SystemBus, SessionBus
from gi.repository import GLib
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
#include <stdio.h>
#include <string.h>
#define OPEN_BRACKETS 5
#define STR_LENGTH 10
void gen(int length, int opened, int closed, char* str) {
if (opened + closed == 2 * length) {
printf("%s\n", str);
return;