Skip to content

Instantly share code, notes, and snippets.

View oprypin's full-sized avatar

Oleh Prypin oprypin

View GitHub Profile
@oprypin
oprypin / crystalize.py.diff
Created June 1, 2015 18:17
crystalize.py PCRE
diff --git a/crystalize.py b/crystalize.py
index 8f85408..d53a4ac 100755
--- a/crystalize.py
+++ b/crystalize.py
@@ -76,7 +76,7 @@ code = []
keywords = 'alias and begin break case class def defined do else elsif end ensure false for if in module next nil not or redo rescue retry return self super then true undef unless until when while yield BEGIN END'.split()
-lib_name = 'Lib'
+lib_name = 'PCRE'
@oprypin
oprypin / examples.md
Last active August 29, 2015 14:22
crystalize.py examples
@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
#!/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 / 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)
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-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"
@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 / 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
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