Skip to content

Instantly share code, notes, and snippets.

View alanduan's full-sized avatar

Alan Duan alanduan

View GitHub Profile
@alanduan
alanduan / Create_IsoCam.py
Created July 11, 2020 05:45 — forked from krasnovpro/Create_IsoCam.py
Creates a true isometric camera in blender
# This script creates two kinds of isometric cameras.
#The one, TrueIsocam called camera, is the mathematical correct isometric camera with the 54.736 rotation to get the 30 degrees angles at the sides of the rhombus.
#The other, GameIsocam called camera, is a camera with which you can render isometric tiles for a 2d game. Here we need a 60 degrees angle instedad of the 54.736 one to get a proper stairs effect and a ratio of 2:1
# Then there is the special case with a 4:3 ratio, which is button 3. You can also make 2D games with that one. The view is more topdown though as with a 2:1 ratio of the traditional game iso view.
# The fourth button creates a simple groundplane where you can place your stuff at.
#You can of course set up everything by hand. This script is a convenient solution so that you don't have to setup it again and again.
# The script is under Apache license
@alanduan
alanduan / write_shared_memory.cc
Created June 10, 2020 23:21
time how fast we can write to shared memory
#include <fstream>
#include <cstdint>
#include <ctime>
#include <iostream>
#include <boost/interprocess/file_mapping.hpp>
#include <boost/interprocess/mapped_region.hpp>
int main()
{
import itertools
def prime():
primes = [2]
yield 2
for candidate in itertools.count(3):
if all(candidate % i != 0 for i in primes if i * i <= candidate):
primes.append(candidate)
yield candidate
@alanduan
alanduan / flat.py
Created February 1, 2018 08:41
flatten data structure
def flat(content):
path = []
flatten(content, path)
def flatten(content, path):
if type(content) is list or type(content) is tuple:
for index, node in enumerate(content):
cur_path = path[:]
cur_path.append(str(index))
flatten(node, cur_path)
import logging
logger = logging.getLogger(__file__)
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
logger.info('this is a test message')
import turtle
import math
from fibonacci import fibonacci_generator as number_generator
if __name__ == '__main__':
for i, v in enumerate(number_generator()):
if v in [0, 1]:
continue
if i > 200:
@alanduan
alanduan / fibonacci.py
Created December 13, 2016 01:00
nth fibonacci
import unittest
class FibonacciTest(unittest.TestCase):
def test_sequence(self):
self.assertEqual(fibonacci_nth(0), 0)
self.assertEqual(fibonacci_nth(1), 1)
self.assertEqual(fibonacci_nth(2), 1)
self.assertEqual(fibonacci_nth(3), 2)
self.assertEqual(fibonacci_nth(4), 3)
@alanduan
alanduan / encode.cpp
Created September 14, 2016 07:40
mess up with encoding.
#include <iostream>
#include <locale>
#include <algorithm>
int main()
{
wchar_t data[] = L"\u00b1\u03b1\U00024b62"; // { 0xb1 : 0x3b1 : 0xd852 : 0xdf62 : 0 } on windows, while { 0xb1, 0x3b1, 0x24b62, 0 } on linux
//char16_t data[] = u"\u00b1\u03b1\U00024b62"; // works! actually saved as { 0xb1, 0x3b1, 0xd852, 0xdf62, 0 }
//char32_t data[] = U"\u00b1\u03b1\U00024b62"; // works! as { 0xb1, 0x3b1, 0x24b62, 0 }
@alanduan
alanduan / test_main.cc
Last active September 4, 2016 22:57
Google Mock & Boost Test, support static lib and dynamic lib
#define BOOST_TEST_MODULE Demo Boost Test & GMock
#include <boost/test/unit_test.hpp>
#include <gmock/gmock.h>
class HookupListner : public ::testing::EmptyTestEventListener
{
public:
void OnTestPartResult(const ::testing::TestPartResult& result)
{
boost::unit_test::unit_test_log
#include <iostream>
struct one_bit_t
{
signed value : 1;
};
int main()
{
one_bit_t a;