Skip to content

Instantly share code, notes, and snippets.

@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 / getUserByToken.php
Created April 1, 2020 17:26
Firebase Auth - Verify ID token, and get user info in PHP with CURL
function getUserByToken($token)
{
$data = array("idToken" => $token);
$data_string = json_encode($data);
$ch = curl_init('https://identitytoolkit.googleapis.com/v1/accounts:lookup?key=' . API_KEY);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
@TheBojda
TheBojda / pygad_reinforcement.ipynb
Last active December 22, 2022 14:57
PyGAD (Genetic Algorithm) reinforcement learning example with Tensorflow and OpenAI Gym (CartPole v1)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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 / pygad_torch_pool.py
Created January 30, 2021 09:35
Reinforcement learning on multiple CPUs with Genetic Algorithm using PyGAD, PyTorch, Open AI Gym (CartPole) and multiprocessing.Pool
import time
import gym
import numpy as np
import pygad.torchga
import pygad
import torch
import torch.nn as nn
from multiprocessing import Pool
@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 / pygad_reinforcement.py
Created January 24, 2021 09:41
Reinforcement learning with genetic algorithm (PyGAD and OpenAI Gym - CartPole-v1)
import gym
import numpy as np
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
import pygad.kerasga
import pygad
def fitness_func(solution, sol_idx):
global keras_ga, model, observation_space_size, env
@TheBojda
TheBojda / todo_react.js
Created February 9, 2020 16:23
Simple TODO react native app
// Simple TODO react native app
// based on https://codeburst.io/todo-app-with-react-native-f889e97e398e
import React, { Component } from 'react';
import { StyleSheet, Text, View, FlatList, TextInput, Keyboard, Button } from 'react-native';
const isAndroid = Platform.OS == "android";
export default class App extends Component {
@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 / tensorflow_cnn_model_training.py
Created October 21, 2019 08:19
TensorFlow CNN model training example
# TensorFlow CNN model training example
# based on https://www.tensorflow.org/tutorials/images/cnn
from __future__ import absolute_import, division, print_function, unicode_literals
import tensorflow as tf
from tensorflow.keras import datasets, layers, models
import matplotlib.pyplot as plt