Skip to content

Instantly share code, notes, and snippets.

@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;
@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 / 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