Skip to content

Instantly share code, notes, and snippets.

View bararchy's full-sized avatar

Bar Hofesh bararchy

View GitHub Profile
@bararchy
bararchy / overloads.cr
Created January 8, 2017 18:09
overloads in crystal
def foo(bar : String)
puts "#{bar} is a string"
end
def foo(bar : Int32)
puts "#{bar} is an Int"
end
etc...
@bararchy
bararchy / types.cr
Created January 8, 2017 17:45
Crystal type examples
# This is an array if Int32
a = [] of Int32
# or we can also do this
a = Array(Int32)
# or even
a = [1,2,3]
# this is a Hash
a = {} of Symbol => Int32
# or
@bararchy
bararchy / krb5.cr
Created June 28, 2016 12:54
Krb5 Bindings
@[Link("krb5")]
lib LibKRB
fun krb5_init_context(buff : UInt8*) : UInt32
fun krb5_free_context(buff : UInt8*) : Void
end
class Krb5
@bararchy
bararchy / example.rb
Last active February 15, 2016 13:06
Sphere Protocol
require 'json'
require 'colorize'
require 'socket'
puts 'Usage: ruby test_client server port dir_path'.bold
server = ARGV[0]
port = ARGV[1]
path_to_dir = ARGV[2]
serial = ARGV[3]
profile = ARGV[4]
@bararchy
bararchy / bencher.rb
Last active October 26, 2015 11:07
Benchmarking Hash
require 'openssl'
require 'benchmark'
class Testing_Hash
def initialize(a_message, integer)
@message = a_message
@integer = integer
end
@bararchy
bararchy / sort.c
Created August 5, 2015 08:09
Bubble sort
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
void shuffle(int *array, size_t n);
void print_array(int *my_array, int array_size);
int main(int argc, char *argv[]){
Error in ./src/rsaccess-web.cr:31: instantiating 'RSAccessApp#serve()'
app.serve
^~~~~
instantiating 'serve(Int32)'
in /home/unshadow/Desktop/git-projects/Amethyst/src/amethyst/base/app.cr:45: instantiating 'HTTP::Server#listen()'
server.listen
in /home/unshadow/Desktop/git-projects/Amethyst/src/amethyst/support/sendable.cr:32: macro didn't expand to a valid program, it expanded to:
================================================================================
--------------------------------------------------------------------------------
1. case method
2.
3.
4. else
5. raise WrongInstanceMethod.new("Amethyst::Base::Controller+", "#{method}")
6. end
# Maintainer: Jonne Haß <me@jhass.eu>
# Contributor: Mikkel Kroman <mk@maero.dk>
pkgname=crystal-git
pkgver=0.7.4.r0.g42efdbf
_last_release="0.7.4-1"
pkgrel=1
pkgdesc="The Crystal Programming Language"
arch=('i686' 'x86_64')
url="http://crystal-lang.org"
## Former code which works:
Thread.new(server.accept) do |client|
if client
addr = client.peeraddr if client
log.info("Client connected from IP: #{addr.ip_address} and port: #{addr.ip_port}") if log && addr
package_parser(client, log)
client.close if client
end
end