- Download all files.
- Build the Crystal part:
crystal build --release --cross-compile --prelude ./no_main library.cr
^ You can leave this out
^ We want to link ourselves!
^ Use our custom prelude!
/* Compile: $ g++ -std=c++11 -o amd64 amd64.cpp */ | |
#include <cstdio> | |
#include <cstdlib> | |
#include <cstdint> | |
#include <cstring> | |
#include <sys/mman.h> | |
// Helper enums so we don't have to poke in bytes directly. | |
// You can find the documentation of all of these in the *free* AMD64 specification: |
# This code is meant for debugging purposes. Its performance is probably bad, | |
# it's just meant to work for some hacky scripts you throw out tomorrow :) | |
# Create an instance of `Bitmap`, passing the file (IO or string), the width and height. | |
# Then push one (or more) 32bit pixels in ARGB format using `Bitmap#<<`. | |
# Pixel format is thus: 0xAARRGGBB (Alpha is highest byte, blue lowest). | |
# (Alpha is ignored by most programs however) | |
class Bitmap | |
MAGIC = "BM" | |
class Boleite::InputReceiver | |
def process(event : InputEvent) | |
execute_all(@actions, event) unless event.claimed? | |
execute_all(@persistent_actions, event) | |
end | |
private def execute_all(actions, event) | |
actions.each{|act| act.execute(event) if act.interested?(event)} | |
end | |
end |
waiter = Channel(Nil).new | |
var = "Hello" | |
spawn do | |
waiter.receive | |
var = 5 | |
end | |
puts "var is a #{typeof(var)}" | |
puts "var right now is a #{var.class}" |
class Foo | |
@stuff : String | Int32 | |
@waiter = Channel(Nil).new | |
def initialize(@stuff) | |
spawn do | |
@waiter.receive # Simulate waiting for some IO | |
@stuff = "Oh noes!" # And store the result of it | |
end |
require "llvm" | |
# Initialize LLVM. There's also `LLVM.init_arm` if that's what you use. | |
LLVM.init_x86 | |
# The context of everything we'll do. Main book-keeping structure. | |
ctx = LLVM::Context.new | |
# Code can be separated in different modules. A module can't directly interact | |
# with another module. If you'd do that, you'd have to link them. |
# Papierkorb suggestion | |
class Foo | |
include CrystalClear | |
requires var > 5 # Pushes "var > 5" into SOME_ARRAY | |
ensures result.query? # Pushes "result.query?" into SOME_ARRAY | |
contract def foo # Expands to the def, processes SOME_ARRAY, and clears it out for the next method | |
# Code | |
end |
# Requiring stuff from Crystals standard library | |
require "macros" | |
require "object" | |
require "comparable" | |
require "exception" | |
require "iterable" | |
require "iterator" | |
require "indexable" | |
require "primitives" |
#!/usr/bin/env ruby | |
# A script to bulk change file associations. Intended for KDE, but might work | |
# with other XDG conforming software. Run it without arguments to see how to | |
# use it. Created by me out of frustration, so the code just works ;) | |
require "inifile" # gem install inifile | |
ASSOC_FILE = "#{ENV['HOME']}/.config/mimeapps.list" | |
ASSOC_FILE_BAK = "#{ASSOC_FILE}.bak" |