Skip to content

Instantly share code, notes, and snippets.

View oprypin's full-sized avatar

Oleh Prypin oprypin

View GitHub Profile
@oprypin
oprypin / rounded_polygon_shape.cr
Last active September 19, 2016 14:34
CrSFML: Rounded polygon shape
class RoundedPolygon < SF::Shape
def initialize
super()
@result = [] of SF::Vector2f
end
def assign(points, radius : Number)
@result.clear
set -x
for branch in master feature/assert; do
git checkout $branch && make clean && time make &&
time ./bin/crystal build -o .build/all_spec spec/all_spec.cr && time .build/all_spec
done
+ for branch in master feature/assert
+ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
@oprypin
oprypin / assert.cr
Last active August 24, 2016 23:02
Power Assert 2
require "compiler/crystal/syntax"
include Crystal
class AssertToSVisitor < ToSVisitor
getter locations = [] of Int32
def visit_any(node)
if node.class.name.ends_with?("Literal") || node.is_a? Path
@str << node.to_s
return false
@oprypin
oprypin / sfml.diff
Created August 13, 2016 07:48
API changes between SFML 2.3 and 2.4
SoundBufferRecorder.hpp
+ ~SoundBufferRecorder();
SoundRecorder.hpp
+ void setChannelCount(unsigned int channelCount);
+ unsigned int getChannelCount() const;
SoundSource.hpp
+ SoundSource& operator =(const SoundSource& right);
BlendMode.hpp
- Add, ///< Pixel = Src * SrcFactor + Dst * DstFactor
- Subtract ///< Pixel = Src * SrcFactor - Dst * DstFactor
@oprypin
oprypin / examples.diff
Created August 10, 2016 14:53
Showcase of API differences in the new CrSFML
diff --git a/examples/diagnostics.cr b/examples/diagnostics.cr
index 3e1a86a..6266e54 100644
--- a/examples/diagnostics.cr
+++ b/examples/diagnostics.cr
@@ -7,8 +7,8 @@ $font : SF::Font
$font = SF::Font.from_file("resources/font/Ubuntu-R.ttf")
$window = SF::RenderWindow.new(
- SF.video_mode(800, 600), "Diagnostic information",
- settings: SF.context_settings(depth: 24, antialiasing: 8)
@oprypin
oprypin / two_digits.py
Last active August 1, 2016 19:37
Fully automatic solver of Two Digits http://store.steampowered.com/app/371330/
print("Starting...")
import sys
import collections
import itertools
import subprocess
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
@oprypin
oprypin / prompt_return_code.py
Last active March 17, 2022 22:14
Xonsh formatter dict: last return code, duration of last command
last_duration = last_return = 0
orig_append = __xonsh_history__.append
def append(cmd):
nonlocal last_duration, last_return
last_return = cmd['rtn']
a, b = cmd['ts']
last_duration = b - a
orig_append(cmd)
__xonsh_history__.append = append
@oprypin
oprypin / json_spec.cr
Created July 19, 2016 21:54
power_assert
require "spec"
require "power_assert"
require "json"
describe JSON::Any do
describe "casts" do
it "gets nil" do
assert JSON.parse("null").as_nil == nil
end
@oprypin
oprypin / new_assert.txt
Last active August 25, 2016 16:47
assert comparison
FFFFF
Failures:
1) JSON::Any gets float
Failure/Error: assert JSON.parse("123.45").as_f32 == 123.45
assert JSON.parse("123.45").as_f32 == 123.45
| | |
| | false : Bool
@oprypin
oprypin / make_disk.sh
Last active June 24, 2016 09:37
Run ceph test cluster by creating a btrfs file system in a file in RAM
set -e
cd /tmp
dd if=/dev/zero of=ceph_fs bs=1024 count=3145728 # 3 GiB
sudo losetup /dev/loop0 || sudo losetup /dev/loop0 ceph_fs
sudo mkfs.btrfs -f /dev/loop0
cd /path/to/ceph/src/
sudo mount /dev/loop0 dev
sudo mount /dev/loop0 run
sudo chown -R $USER: dev run