Skip to content

Instantly share code, notes, and snippets.

@1000copy
1000copy / hashtest.zig
Created February 22, 2024 13:49
hashtest.zig
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
@1000copy
1000copy / hashtable.c
Created February 21, 2024 12:57 — forked from phsym/hashtable.c
An hashtable implementation in C
/*
* 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
@1000copy
1000copy / lisp.zig
Created December 27, 2023 02:05
A simple LISP interpreter,written in Zig language
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 {
// 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
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{
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) {
@1000copy
1000copy / chapter02-i18n.cpp
Created August 1, 2022 06:09
chapter02-i18n.cpp
#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 = "你好";
@1000copy
1000copy / valueVSrefVSpointer.cpp
Created August 1, 2022 03:23
valueVSrefVSpointer.cpp
#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;
@1000copy
1000copy / lisp.cpp
Last active July 5, 2022 06:05 — forked from ofan/lisp.cpp
Lisp interpreter in 90 lines of C++
#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(); }
// v2ex不容易看到对话。于是我写了一个爬虫,抓出两人的对话,谁是谁非,大家自行判断。哈哈有趣。
/*
Title:从v2ex内提取两人的对话
Paramters:PostID,userid1,userid2
Procedure:
1. 提出对应帖子的全部回复
2. 过滤条件:是IDList内的id发出的帖子,并且帖子内@了另外一个id的
3. 帖子字段保留
API:
获取指定主题下的回复