Skip to content

Instantly share code, notes, and snippets.

#include <stdbool.h>
#include <stdint.h>
#include "convert_utf8.h"
#define UTF8_SINGLE_BYTE_CONTROL_MASK 0x80
#define UTF8_SINGLE_BYTE_CONTROL_VALUE 0x00
// Returns true if `byte` is standalone in UTF8.
-module(proc_lib_instance).
-export([start_link/0,
ping/1]).
-export([init/1,
system_continue/3,
system_code_change/4,
system_terminate/4]).
-module(util_record).
-compile(export_all).
-define(NAME_ELEMENT, 1).
-define(VERSION_ELEMENT, 2).
-spec update_record(atom(), fun(), tuple()) -> tuple().
-module(code_change_test).
% How to use:
%
% 1. Compile with first st record definition uncommented
%
% 2. Start several processes:
% 1> {ok, Pid1} = code_change_test:start().
% init
% {ok,<0.34.0>}
-module(or_or_or).
-compile(export_all).
f1(X) ->
if
length(X) =:= 1; size(X) =:= 1 ->
okay;
true ->
nope
@mietek
mietek / zosia.c
Created March 1, 2012 13:34
DTrace contest source
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define CODE_LEN 16
const unsigned char ENCRYPTED[][CODE_LEN + 1] = {
// ad8b0a518f4e717b
@mietek
mietek / zosia.sh
Created March 1, 2012 13:36
DTrace contest solutions
# ad8b0a518f4e717b
strings zosia
# b96fce77a01aa3f1
dtrace -c ./zosia -n 'syscall::open:entry /execname == "zosia"/ { printf("code b: %s", copyinstr(arg0)); }'
# c27c4c97a2cca1e5
dtrace -c ./zosia -n 'syscall::write:entry /execname == "zosia"/ { printf("code c: %s", copyinstr(arg1)); }'
# da2c30abab3f9ba0
@mietek
mietek / sort_c.c
Created April 8, 2012 17:03
Sorting C strings in C and C++
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int my_string_compare(const void* a, const void* b) {
return strcmp(*(const char**)a, *(const char**)b);
}
int main() {
const char* s[] = {"dalet", "gimel", "bet", "aleph"};
{-# LANGUAGE FlexibleInstances,
MultiParamTypeClasses,
ScopedTypeVariables,
TypeFamilies,
TypeOperators,
UndecidableInstances #-}
{-# OPTIONS_GHC -funbox-strict-fields #-}
module Main where
from __future__ import division
def is_letter(c):
return c >= 'A' and c <= 'Z' or c >= 'a' and c <= 'z'
def score_word(s):
return len(filter(is_letter, s)) / len(s)
def average(s):
return sum(s) / len(s)