This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "http/client" | |
client = HTTP::Client.new "slack.com" | |
i = 0 | |
loop do | |
response = client.get "/api/users.list" | |
pp response.body | |
pp i | |
i += 1 | |
sleep 30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cc -c foo.c -o foo.o | |
#include <stdlib.h> | |
void** global_data; | |
void foo_set(void* data) { | |
void** ptr = (void**)malloc(sizeof(data)); | |
*ptr = data; | |
global_data = ptr; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Foo | |
def foo | |
@foo + 1 | |
end | |
end | |
class Bar < Foo | |
def initialize | |
@foo = 1 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Error in ./libs/frank/frank.cr:21: instantiating 'HTTP::Server#listen()' | |
server.listen | |
^~~~~~ | |
in /Users/asterite-manas/Projects/crystal/src/http/server/server.cr:37: instantiating 'handle_client(TCPSocket+)' | |
handle_client(server.accept) | |
^~~~~~~~~~~~~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = 1 | |
b = -3 | |
b.abs = 3 | |
a + b = -2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
record Cell, car, cdr | |
alias List = Nil | (-> Cell) | |
def inf(x = 0) | |
inf :: -> Cell | |
inf = -> { Cell.new(x, inf) } | |
end | |
def nat(x = 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <dirent.h> | |
#include <stdio.h> | |
int main() { | |
DIR *dirp; | |
struct dirent *dp; | |
dirp = opendir("."); | |
if (dirp == NULL) | |
return (1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dir.list(".") do |dir, type| | |
puts "#{dir}: #{type}" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro def_observer_pattern(name) | |
{% up = name.id %} | |
{% down = name.stringify.downcase.id %} | |
module {{up}}Observer | |
abstract def on_{{down}}(obj) | |
end | |
module {{up}}Observable | |
def add_{{down}}_observer(observer : {{up}}Observer) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module NumObserver | |
abstract def on_num(num) | |
end | |
module NumObservable | |
def add_observer(observer : NumObserver) | |
num_observers = @num_observers ||= [] of NumObserver | |
num_observers << observer | |
end |