Skip to content

Instantly share code, notes, and snippets.

View zwzmzd's full-sized avatar

Wenzhe Zhou zwzmzd

View GitHub Profile
@w1ndy
w1ndy / mktime_quick.hpp
Last active November 23, 2023 07:40
Lock-free version of mktime (converting "struct tm" to UNIX timestamp) without considering timezone
#pragma once
#include <cassert>
#include <ctime>
#define ISLEAP(x) (((x) % 4 == 0 && (x) % 100 != 0) || ((x) % 400 == 0))
#define LEAPDELTA(x, y) ((ISLEAP(x) && (y) >= 2) ? 86400 : 0)
time_t mktime_quick(struct tm const &p)
{
@fclairamb
fclairamb / rapidjson_gen_json.cpp
Created January 5, 2016 13:04
Write some JSON using a rapidjson library
#ifdef SHELL
g++ -Wall -Werror -g -I../../cclib/rapidjson/include $0 && ./a.out
exit 0
#endif
// Output is:
// {"project":"rapidjson","stars":11}
// {"Name":"XYZ","Rollnumer":2,"array":["hello","world"],"Marks":{"Math":"50","Science":"70","English":"50","Social Science":"70"}}
// {"FromEmail":"sender@gmail.com","FromName":"Sender's name","Subject":"My subject","Recipients":[{"Email":"recipient@gmail.com"}],"Text-part":"this is my text"}
@pokstad
pokstad / rediswebpy.py
Created September 7, 2011 23:02
Redis session store backend for web.py
import redis
import web
SESSION = 'SESSION:'
class RedisStore(web.session.Store):
"""Store for saving a session in redis:
import rediswebpy
session = web.session.Session(app, rediswebpy.RedisStore(), initializer={'count': 0})