Skip to content

Instantly share code, notes, and snippets.

fn try<T: Send>(f: ~fn(~fn(~str) -> !) -> T) -> Result<T, ~str> {
let (wr, rd) = task::stream();
let result: Result<T, ()> = do tasks::try |move wr| {
let fail_: fn~(~str) -> ! = fn~(x: ~str) -> ! { wr.send(x); fail; };
f(fail_)
};
return match move result {
Ok(move v) => Ok(move v),
Err(_) => match rd.try_recv() {
Some(move s) => Err(move s),
use std;
import result::{result, ok, chain};
fn read_file(filename: str) -> result<@str, @str> {
ret ok(@("<contents of " + filename + ">"));
}
fn parse_buf(buf: @str) -> @str {
ret @("<parsed: " + *buf + ">");
}
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>
size_t check_malloc_size(void* p, size_t n) {
int fd[2];
pid_t child;
import std.stdio;
import std.math;
import std.array;
import std.format;
struct Dimension(int m, int kg, int s) {
@disable this();
}
template GetBaseType(T) {
#include <gtk/gtk.h>
void on_realize(GtkWidget* widget, gpointer user_data);
int main(int argc, char* argv[]) {
GtkWidget* widget;
gtk_init(&argc, &argv);
widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
class Foo {
public:
template<typename T>
void bar() {
T::derp();
}
};
class Helper {
public:
Reading symbols from /home/ben/code/repos/OpenXcom/bin/openxcom...done.
(gdb) break XcomRuleset.cpp:1964
Breakpoint 1 at 0x6283c3: file /home/ben/code/repos/OpenXcom/src/Ruleset/XcomRuleset.cpp, line 1964.
(gdb) run
Starting program: /home/ben/code/repos/OpenXcom/bin/openxcom
[Thread debugging using libthread_db enabled]
[New Thread 0x7ffff33fe700 (LWP 16981)]
Breakpoint 1, OpenXcom::XcomRuleset::XcomRuleset (this=0x2bb66c0)
at /home/ben/code/repos/OpenXcom/src/Ruleset/XcomRuleset.cpp:1964
(gdb) break XcomRuleset.cpp:1964
Breakpoint 1 at 0x6283c3: file /home/ben/code/repos/OpenXcom/src/Ruleset/XcomRuleset.cpp, line 1964.
(gdb) run
Starting program: /home/ben/code/repos/OpenXcom/bin/openxcom
[Thread debugging using libthread_db enabled]
[New Thread 0x7ffff33fe700 (LWP 16887)]
Breakpoint 1, OpenXcom::XcomRuleset::XcomRuleset (this=0x2bb8450)
at /home/ben/code/repos/OpenXcom/src/Ruleset/XcomRuleset.cpp:1964
warning: Source file is more recent than executable.
- name: STR_FUSION_BALL_LAUNCHER
cost: 242000
space: 6
time: 400
requirements:
- name: STR_ALIEN_ALLOYS
amount: 1
- name: STR_LASER_CANNON
cost: 182000
space: 6
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#define MSG "and the random number is: "
size_t num_length(long num) {
size_t result;