Skip to content

Instantly share code, notes, and snippets.

@physacco
physacco / getch.c
Created November 8, 2016 07:15
Get char from stdin without pressing enter.
#include <stdio.h>
#include <termios.h>
int getch(void) {
int ch;
struct termios oldt;
struct termios newt;
tcgetattr(STDIN_FILENO, &oldt); /*store old settings */
newt = oldt; /* copy old settings to new settings */
@physacco
physacco / numeric_limits.cpp
Created September 19, 2016 11:33
Example of std::numeric_limits.
#include <iostream>
#include <limits>
template <typename T>
void test_limits() {
T min = std::numeric_limits<T>::min();
T max = std::numeric_limits<T>::max();
std::cout << "min: " << min << std::endl;
std::cout << "max: " << max << std::endl;
}
@physacco
physacco / README.md
Last active December 27, 2023 09:05
Python 3 extension example

Python 3 extension example

Build

python3 setup.py build

Output: build/lib.macosx-10.11-x86_64-3.5/hello.cpython-35m-darwin.so

Run

@physacco
physacco / CMakeLists.txt
Last active November 27, 2023 19:12
MsgPack sample programs.
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.2)
PROJECT(msgpack_test)
SET(CMAKE_CXX_FLAGS_DEBUG "-g -std=c++11")
SET(EXECUTABLES test_vector test_stream test_class test_array test_map1 test_map2)
FOREACH(EXE ${EXECUTABLES})
ADD_EXECUTABLE(${EXE} "${EXE}.cpp")
TARGET_LINK_LIBRARIES(${EXE} msgpack)
@physacco
physacco / CMakeLists.txt
Created July 8, 2016 02:44
Android NDK hello-world program.
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.2)
PROJECT(hello)
SET(PROJECT_ROOT_PATH "${CMAKE_SOURCE_DIR}")
SET(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/bin")
SET(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib")
ADD_EXECUTABLE(hello hello.cpp)
@physacco
physacco / resize_chrome.sh
Created July 7, 2016 02:39
Resize Google Chrome browser on Mac OS X
#!/bin/bash
osascript -e 'tell application "Google Chrome"' -e 'set bounds of front window to {1, 1, 1280, 640}' -e 'end tell'
@physacco
physacco / ando10.d
Created December 22, 2015 19:52
My solutions to paiza POH 7 in D language
import std.stdio;
long factorial(int n) {
long fac = 1;
foreach (i; 1..n+1) {
fac *= i;
}
return fac;
}
@physacco
physacco / ando10.rb
Last active December 17, 2015 11:39
My solutions to paiza POH 7
x=1;1.upto(gets.to_i){|i|x*=i};p x
@physacco
physacco / find_small_images.py
Created March 2, 2015 18:10
Search in current directory for image files that is smaller than specified resolution and optionally remove them.
import os
import re
import sys
import optparse
from PIL import Image
IMAGE_EXT_PATTERN = re.compile(r'\.(jpe?g|png|gif|bmp)', re.IGNORECASE)
def safe_int(string):
try:
@physacco
physacco / Build.sh
Created August 19, 2014 09:24 — forked from AngryAnt/Build.sh
mcs -target:library -out:MyAssembly.dll -r:/Applications/Unity/Unity.app/Contents/Frameworks/UnityEngine.dll MyAssembly.cs