Skip to content

Instantly share code, notes, and snippets.

View oprypin's full-sized avatar

Oleh Prypin oprypin

View GitHub Profile
@oprypin
oprypin / _license.md
Last active March 24, 2020 14:32
Open links in the host OS when clicking them in the guest OS (VirtualBox)

The MIT License (MIT)

Copyright (C) 2015 Oleh Prypin [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

module Indexable(T)
def threadpool_map(workers : Int = 8, chunk_size : Int? = nil, &func : T -> R) forall T, R
mutex = Thread::Mutex.new
cs = chunk_size || (self.size**0.5).ceil.to_i
Array(R).build(self.size) do |result|
index = 0
threads = Array.new(workers) {
Thread.new do
a = b = 0
loop do
@oprypin
oprypin / benchmark.md
Last active August 29, 2015 14:27
Benchmark

crystal run --release bm.cr

class unshift pop unshift push shift push push pop unshift shift each insert length/8 insert length*3/5
array 1.405377 0.685335 0.015142 7.018896 0.000162 0.222118 0.101504
deque 0.000901 0.000897 0.021794 0.019965 0.000303 0.151282 0.301467
@oprypin
oprypin / main.cpp
Last active August 29, 2015 14:27
SFML 2.3: gradual drawing of line shapes + erasing
#include <vector>
#include <cmath>
#include <SFML/Graphics.hpp>
#include "roundendedline.hpp"
int main() {
sf::Vector2f cross[][2] = {
@oprypin
oprypin / 1-tok_gen.py
Last active August 29, 2015 14:27
A tokenizer feeding into parser+builder
# Generator functions in Python give out results one by one, and you can iterate over them in a for-loop
def tokens_generator():
yield "{"
yield "Hash"
yield "("
yield "Int32"
yield ","
yield "Array"
yield "("
yield "Int32"
import dbus
bus = dbus.SessionBus()
proxy = bus.get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
proxy.Notify("app", dbus.UInt32(0), "", "title", "body", dbus.Array([], signature="s"), dbus.Dictionary({}, signature="sv"), 1000)
@oprypin
oprypin / 1.py
Created July 14, 2015 20:26
Inception
%if False:
print(5)
print("a")
print("lol")
for i in range(10):
%if True:
print(6)
print(8)
#!/usr/bin/python3
import subprocess
import re
#repl = {6:2, 7:2} # Mouse buttons to be replaced
repl = {6:8, 7:9} # Mouse buttons to be replaced
out = subprocess.check_output(['xinput', 'list'])
for s in out.decode('utf-8').lower().split('\n'):
try:
@oprypin
oprypin / chipmunk.cr
Created June 1, 2015 18:31
crystalize.py Chipmunk
lib CP
fun message = "cpMessage"(condition : UInt8*, file : UInt8*, line : Int32, is_error : Int32, is_hard_error : Int32, message : UInt8*, ...) : Void
alias Float = Float64
alias HashValue = LibC::SizeT
alias CollisionID = UInt32
alias Bool = UInt8
@oprypin
oprypin / examples.md
Last active August 29, 2015 14:22
crystalize.py examples