// a.c
size_t Chunk_copy(Chunk *src, size_t src_start, Chunk *dst, size_t dst_start, size_t n)
{
if (!Chunk_bounds_check(src, src_start, n)) return 0;
if (!Chunk_bounds_check(dst, dst_start, n)) return 0;
memcpy(dst->data + dst_start, src->data + src_start, n);
This file contains 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
class Mailer < ApplicationMailer | |
def self.my_class_method | |
build_the_mail.deliver_now # this invokes (B) | |
end | |
def build_the_mail # (A) this is the instance method you write | |
mail( | |
# ... | |
) | |
end |
This file contains 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 "./diff" | |
class MyersLinear | |
Window = Struct.new(:left, :top, :right, :bottom) do | |
def width | |
right - left | |
end | |
def height | |
bottom - top |
This file contains 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 Lambda where | |
import Control.Monad (when) | |
import Data.List (nub, sort) | |
data LTerm = Var String | |
| Lambda String LTerm | |
| Apply LTerm LTerm | |
deriving (Eq) |
This file contains 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_relative './pattern' | |
Pattern.define :TmIf, | |
:TmTrue, | |
:TmFalse, | |
:TmZero, | |
:TmSucc, | |
:TmPred, | |
:TmIsZero |
This file contains 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_relative "../myers/linear" | |
class Diff3 | |
def self.merge(o, a, b, differ: MyersLinear) | |
o = o.lines if o.is_a?(String) | |
a = a.lines if a.is_a?(String) | |
b = b.lines if b.is_a?(String) | |
new(o, a, b, differ).tap(&:run) | |
end |
The following based on Myers' original paper.
To use the example from the paper, say you want to calculate the difference between two strings:
This file contains 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 <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
typedef char * BLOB; | |
typedef struct BufferChunk { | |
int length; | |
int cursor; | |
BLOB data; |
This file contains 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 <stdio.h> | |
#include <assert.h> | |
#include <stdlib.h> | |
#include <errno.h> | |
#include <string.h> | |
struct Address { | |
int id; | |
int set; | |
char *name; |
This file contains 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
var crypto = require('crypto'); | |
var key = crypto.randomBytes(32), | |
iv = crypto.randomBytes(12), | |
mode = 'aes-256-gcm'; | |
var message = new Buffer('Hello, world!', 'utf8'); | |