Skip to content

Instantly share code, notes, and snippets.

@TheBojda
TheBojda / cleanup.py
Created April 7, 2025 06:05
Cleanup your projects directory by recusively delete node_modules
#!/usr/bin/env python3
import os
import shutil
def delete_node_modules(root_dir):
for dirpath, dirnames, filenames in os.walk(root_dir):
if 'node_modules' in dirnames:
full_path = os.path.join(dirpath, 'node_modules')
try:
@TheBojda
TheBojda / dicom2png.py
Created April 20, 2024 11:47
Export DICOM medical images (MR, CT, X-Ray, etc.) to PNG files
import os
import pydicom
from PIL import Image
import sys
def save_image(pixel_array, output_path):
if pixel_array.dtype != 'uint8':
pixel_array = ((pixel_array - pixel_array.min()) / (pixel_array.max() - pixel_array.min()) * 255).astype('uint8')
img = Image.fromarray(pixel_array)
@TheBojda
TheBojda / setup.sh
Created May 28, 2022 09:30
VirtualBox settings for installing MacOS Monterey to a VM on Linux
#!/bin/sh
# replace ${VM} with your VM name (ex: MacOSX Monterey)
# replace $RES with your resolution (ex: 1920x1080)
VBoxManage modifyvm "${VM}" --cpuidset 00000001 000106e5 00100800 0098e3fd bfebfbff
VBoxManage setextradata "${VM}" "VBoxInternal/Devices/efi/0/Config/DmiSystemProduct" "iMac19,1"
VBoxManage setextradata "${VM}" "VBoxInternal/Devices/efi/0/Config/DmiSystemVersion" "1.0"
VBoxManage setextradata "${VM}" "VBoxInternal/Devices/efi/0/Config/DmiBoardProduct" "Mac-AA95B1DDAB278B95"
VBoxManage setextradata "${VM}" "VBoxInternal/Devices/smc/0/Config/DeviceKey" "ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
@TheBojda
TheBojda / torch_linear.py
Created May 21, 2022 08:51
Linear regression with PyTorch autograd
import torch
import matplotlib.pyplot as plt
from torch.autograd import Variable
class Model:
def __init__(self):
self.W = Variable(torch.as_tensor(16.), requires_grad=True)
self.b = Variable(torch.as_tensor(10.), requires_grad=True)
@TheBojda
TheBojda / index.ts
Created December 23, 2021 12:51
Ethereum crowdfunding widget
const web3 = new Web3(config.PROVIDER_URL)
const balance = parseInt(await web3.eth.getBalance(config.ETH_ADDRESS))
const canvas = createCanvas(200, 270)
const ctx = canvas.getContext('2d')
ctx.fillStyle = "#aaaaaa"
ctx.fillRect(0, 0, canvas.width, canvas.height)
let qrcode = new Image()
qrcode.src = await QRCode.toDataURL(config.ETH_ADDRESS)
@TheBojda
TheBojda / App.vue
Created August 16, 2021 10:53
libp2p browser chat example in JavaScript with vue.js
<template>
<div>
<p>Your peerId: {{ myPeerId }}</p>
<p>
Other peerId:
<input type="text" style="width: 420px" v-model="otherPeerId" /><button
@click="findOtherPeer"
>
Find
</button>
@TheBojda
TheBojda / App.js
Created August 9, 2021 08:43
Simple Vue.js TODO example with TypeScript and vue-class-component
<template>
<main role="main" class="container">
<div class="card">
<div class="card-body">
<h5 class="card-title">Todo example</h5>
<p class="card-text">Simple TODO app using Bootstrap and Vue.</p>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item" v-for="(todo, idx) in todos" :key="idx">
{{ todo }}
@TheBojda
TheBojda / docker-compose.yaml
Last active July 15, 2021 23:25
Docker compose file for a simple WordPress with MySQL
# Docker compose file for a simple WordPress with MySQL
# source: https://docs.docker.com/samples/wordpress/
version: "3.3"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
@TheBojda
TheBojda / App.tsx
Created May 30, 2021 10:36
Simple todo example in react native using typescript and state hooks
import React, { useState, useEffect } from 'react';
import { StyleSheet, Text, View, Platform, Keyboard, Button, FlatList, TextInput } from 'react-native';
const isAndroid = Platform.OS == "android";
export default function App() {
const [text, setText] = useState('');
const [tasks, setTasks] = useState([{ key: '0', text: "First task" }]);
const [viewPadding, setViewPadding] = useState(0);
@TheBojda
TheBojda / minimalistic-nft-token.sol
Last active May 12, 2021 21:06
Minimalistic NFT Ethereum contract in Solidity
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;
contract NFTToken {
event Mint(address indexed _to, uint256 indexed _tokenId, bytes32 _ipfsHash);
event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);
uint256 tokenCounter = 1;
mapping(uint256 => address) internal idToOwner;