Skip to content

Instantly share code, notes, and snippets.

@physacco
physacco / getch.c
Created Nov 8, 2016
Get char from stdin without pressing enter.
View getch.c
#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 Sep 19, 2016
Example of std::numeric_limits.
View numeric_limits.cpp
#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 Sep 12, 2020
Python 3 extension example
View README.md

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 May 14, 2020
MsgPack sample programs.
View CMakeLists.txt
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 Jul 8, 2016
Android NDK hello-world program.
View CMakeLists.txt
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 Jul 7, 2016
Resize Google Chrome browser on Mac OS X
View resize_chrome.sh
#!/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 Dec 22, 2015
My solutions to paiza POH 7 in D language
View ando10.d
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 Dec 17, 2015
My solutions to paiza POH 7
View ando10.rb
x=1;1.upto(gets.to_i){|i|x*=i};p x
@physacco
physacco / find_small_images.py
Created Mar 2, 2015
Search in current directory for image files that is smaller than specified resolution and optionally remove them.
View find_small_images.py
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:
View Build.sh
mcs -target:library -out:MyAssembly.dll -r:/Applications/Unity/Unity.app/Contents/Frameworks/UnityEngine.dll MyAssembly.cs
You can’t perform that action at this time.