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
const std = @import("std"); | |
const ustreamer = @cImport({ | |
@cInclude("hash.c"); | |
}); | |
pub fn main() !void { | |
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`) | |
std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); | |
// stdout is for the actual output of your application, for example if you | |
// are implementing gzip, then only the compressed bytes should be sent to |
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
/* | |
* Author : Pierre-Henri Symoneaux | |
*/ | |
#include <stdlib.h> | |
#include <string.h> | |
//Hashtable element structure | |
typedef struct hash_elem_t { | |
struct hash_elem_t* next; // Next element in case of a collision |
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
const expect = @import("std").testing.expect; | |
const std = @import("std"); | |
const ArrayList = std.ArrayList; | |
const eql = std.mem.eql; | |
const Allocator = std.mem.Allocator; | |
const print = std.debug.print; | |
const LispError = error{ fnnotdef, symbolnotdef }; | |
pub const String = struct { | |
buffer: ArrayList(u8), | |
pub fn toNumber(self: *String) !f64 { |
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
// src from:https://www.cnswift.org/error-handling | |
struct Item { | |
var price: Int | |
var count: Int | |
} | |
//定义异常-枚举是典型的为一组相关错误条件建模的完美配适类型,关联值还允许错误错误通讯携带额外的信息。比如说,这是你可能会想到的游戏里自动售货机会遇到的错误条件: | |
enum VendingMachineError: Error { | |
case invalidSelection | |
case insufficientFunds(coinsNeeded: Int) | |
case outOfStock |
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
import UIKit | |
class Statement{ | |
var db :OpaquePointer? | |
var Statement: OpaquePointer? | |
init(_ db :OpaquePointer?) { | |
self.db = db | |
} | |
func prepare(_ sql : String) throws{ | |
let presult = sqlite3_prepare_v2(db, sql, -1, &Statement, nil) | |
if presult != SQLITE_OK{ |
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
import UIKit | |
class CellData{ | |
var _str:String | |
var _b : Bool | |
var str:String{get{return _str}set(value){_str = value}} | |
var b : Bool{get{return _b}set(value){ | |
_b = value | |
arr.u(self) | |
}} | |
init(str: String, b: Bool) { |
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 <iostream> | |
#include <assert.h> | |
#include <tchar.h> | |
int main(){ | |
//single byte | |
const char* str1 = "hello"; | |
assert(strlen(str1) == 5); | |
// error for double byte | |
const char* str2 = "你好"; |
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 <iostream> | |
#include <assert.h> | |
void swap(int a, int b) { | |
int c = a; | |
a = b; | |
b = c; | |
assert(a == 1 && b == 0); | |
} | |
void swap_pointer(int* a, int* b) { | |
int c = *a; |
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 <iostream> | |
#include <sstream> | |
#include <string> | |
#include <vector> | |
#include <list> | |
#include <map> | |
// return given mumber as a string | |
std::string str(long n) { std::ostringstream os; os << n; return os.str(); } |
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
// v2ex不容易看到对话。于是我写了一个爬虫,抓出两人的对话,谁是谁非,大家自行判断。哈哈有趣。 | |
/* | |
Title:从v2ex内提取两人的对话 | |
Paramters:PostID,userid1,userid2 | |
Procedure: | |
1. 提出对应帖子的全部回复 | |
2. 过滤条件:是IDList内的id发出的帖子,并且帖子内@了另外一个id的 | |
3. 帖子字段保留 | |
API: | |
获取指定主题下的回复 |
NewerOlder