Skip to content

Instantly share code, notes, and snippets.

View webuniverseio's full-sized avatar

Sergey Zarovskiy webuniverseio

View GitHub Profile
@webuniverseio
webuniverseio / Dragon.swift
Last active July 21, 2022 16:45
Swift class based fighting game
import Foundation
class Dragon: Enemy {
let wings = 2
override var type: String {
"Dragon"
}
override init(strength: Int) {
super.init(strength: strength * 2)
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var bar: UIProgressView!
override func viewDidLoad() {
super.viewDidLoad()
bar.alpha = 0
}
@webuniverseio
webuniverseio / calc.swift
Last active July 21, 2022 16:32
iOS projects
import Foundation
calculator()
func calculator() {
let a = Int(readLine()!)! //First input
let b = Int(readLine()!)! //Second input
do {
try add(n1: a, n2: b)
try subtract(n1: a, n2: b)
@webuniverseio
webuniverseio / google-meet-fullscreen-bookmarklet.js
Last active February 22, 2022 17:20 — forked from john-humi/bookmartlet.js
Google Meet FullScreen
javascript:!function(){const e=`button-${window.__meetsRandomNumber=window.__meetsRandomNumber||Math.floor(1e6*Math.random())}`;[...document.getElementsByClassName(e)].forEach((e=>e.remove())),[...document.getElementsByTagName("video")].forEach((function(n){const t=document.createElement("button");t.setAttribute("tabindex",1),t.setAttribute("class",e),t.setAttribute("style","\n z-index: 999999999;\n background: white;\n width: 28px;\n height: 28px;\n position: absolute;\n right: 50px;\n display: block;\n border-radius: 14px;\n margin: 8px;\n background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4NCjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMjAiIGhlaWdodD0iMjAiIHZpZXdCb3g9IjAgMCAyMCAyMCI+DQogIDx0aXRsZT4NCiAgICBmdWxsc2NyZWVuDQogIDwvdGl0bGU+DQogIDxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgZD0iTTEgMXY2aDJWM2g0VjFIMXptMiAxMkgxdjZoNnYtMkgzdi00em0xNCA0aC00djJoNnYtNmgtMnY0em0wLTE2aC00djJoNHY0aDJWMWgtMnoiLz4NCjwvc
@webuniverseio
webuniverseio / mouse.ahk
Last active February 21, 2022 02:44
Windows Mouse Keys replacement using AutoHotKey
#SingleInstance Force
varSlowStep := 10
varFastStep := 75
pressingUp := False
pressingDown := False
pressingLeft := False
pressingRight := False
lastHorizontal := 0
lastVertical := 0
@webuniverseio
webuniverseio / fetchThenRender.js
Last active February 15, 2022 20:15
exercise of fetching in random order, but rendering in logical order
function fetchAndLog(urls) {
const pending = new Map()
let lastProcessed = -1
urls.map((x, i) => {
return fetch(x).then(x => {
if (lastProcessed === i - 1) {
console.log(x.json())
checkPending(++lastProcessed)
} else {
pending.set(i, x.json())
@webuniverseio
webuniverseio / index.js
Created January 19, 2022 22:51
Event queue with max limit and slow/fast scheduling
let status = 'idle'
export const getStatus = () => status
let timerId
const clearTimer = () => clearTimeout(timerId)
const scheduleQueueCheck = ms => {
clearTimer()
timerId = setTimeout(checkQueue, ms)
}
@webuniverseio
webuniverseio / index.html
Created December 25, 2021 17:39
Handle hash changes without adding to page history
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body {
display: grid;
@webuniverseio
webuniverseio / example.js
Created December 5, 2021 01:33
Hooks internals
// https://www.swyx.io/hooks/, https://www.youtube.com/watch?v=KJP1E-Y-xyo
const React = (function() {
let hooks = []
let i = 0
function useState(init) {
const state = hooks[i] || init
const currentIndex = i
const setState = newVal/*?*/ => hooks[currentIndex] = newVal
i++
return [state, setState]
@webuniverseio
webuniverseio / 1.starting.js
Last active December 5, 2021 19:20
reading order
// https://epicreact.dev/why-you-shouldnt-put-refs-in-a-dependency-array/
import * as React from 'react'
import * as ReactDOM from 'react-dom'
function UsernameForm({
initialUsername = '',
onSubmitUsername,
}) {
const [username, setUsername] = React.useState(initialUsername)
const [touched, setTouched] = React.useState(false)