Skip to content

Instantly share code, notes, and snippets.

View videlalvaro's full-sized avatar

Alvaro Videla videlalvaro

View GitHub Profile
func RuneCount(buffer []byte) int {
index, count := 0, 0
for index < len(buffer) {
if buffer[index] < RuneSelf {
index++
} else {
_, size := DecodeRune(buffer[index:])
index += size
}
count++
@videlalvaro
videlalvaro / single_letter.go
Last active September 25, 2018 22:52
single_letter.go
func RuneCount(b []byte) int {
i, n := 0, 0
for i < len(b) {
if b[i] < RuneSelf {
i++
} else {
_, size := DecodeRune(b[i:])
i += size
}
n++
package com.example.store.user;
/**
* Implements a user for our store.
*/
public class User {
private String name;
public User(String name) {
this.name = name;
}
include ../umbrella.mk
<?php
use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Message\AMQPMessage;
use PhpAmqpLib\Wire\AMQPTable;
include(__DIR__ . '/config.php');
$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$ch = $conn->channel();
-module(shiftand).
%% shiftand:match("announce", "annual_announce").
-export([match/2]).
match(Pattern, Text) ->
PatLen = length(Pattern),
BitMaskTable = init_table(Pattern),
MatchMask = 1 bsl (PatLen - 1),
<?php
include(__DIR__ . '/config.php');
use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Message\AMQPMessage;
$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$ch = $conn->channel();
%% run this on the CLI:
%% start erlang: erl +K true
c(memory).
%% file size is arbitrary but too big will make the VM crawl with what follows
{ok, Bin} = file:read_file("my_at_least_3MB_file.something").
L = binary_to_list(Bin).
Pid = memory:start().
%% keep N low, a value of 100 makes my VM unresponsive in my 16GB of RAM Retina Mac.
@videlalvaro
videlalvaro / fold_example.erl
Created April 27, 2015 14:24
blog post example
%% compile and run fold_example:test().
%% Records used here were taken from RabbitMQ's source code.
-module(fold_example).
-compile(export_all).
-record('P_basic',
{content_type,
content_encoding,
headers,
@videlalvaro
videlalvaro / gist:9f8b03bff46236bd0a71
Last active August 29, 2015 14:19
You’ve found a bug in Cairngorm.
REASON FIVE: You’ve found a bug in Cairngorm.
If you find a bug in Cairngorm, there’s a really good chance it’s too
early for you to be using it in mission critical projects. I state
this with confidence, because many years ago I was a C developer who
kept finding bugs in Kernighan and Ritchie’s C compiler. Every day,
I’d find something wrong with the compiler – in fact, come to think of
it, I think I was responsible for finding some real clangers in the
Pascal compiler on SunOS as well, back in the day.