Skip to content

Instantly share code, notes, and snippets.

View usagi's full-sized avatar
🍣
Sushi

USAGI/USAGI.NETWORK usagi

🍣
Sushi
View GitHub Profile
#include <random>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <forward_list>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <chrono>
material_t( aiMaterial* material, const std::string& path_prefix = "" )
{
// マテリアルカラー
{
aiColor3D result;
if( material -> Get( AI_MATKEY_COLOR_DIFFUSE, result ) == aiReturn_SUCCESS )
_diffuse = { result.r, result.g, result.b };
if( material -> Get( AI_MATKEY_COLOR_AMBIENT, result ) == aiReturn_SUCCESS )
_ambient = { result.r, result.g, result.b };
if( material -> Get( AI_MATKEY_COLOR_SPECULAR, result ) == aiReturn_SUCCESS )
@usagi
usagi / map_nearest_two_point.cxx
Last active August 29, 2015 14:00
mapに対してある値の近傍2点の値を取り出したいのです。
#include <map>
#include <string>
#include <iostream>
auto main() -> int
{
// ある値の近傍2点を求めたい map がありました。
const std::map< double , std::string > m = { {0.0, "hello"}, {0.111,"world"}, {0.234, "!!!!"} };
// upper_boundである値に対して「より大きい」キーのイテレーターを取得しました。
auto upper_bound = m.upper_bound( 0.110 );
<?php
echo "More hello, world";
?>
// 標準入出力やエラー出力を扱うためのC++標準ライブラリーの読み込み
#include <iostream>
// 1. main関数に int argc, char** argv は使わないのなら要らない
// 2. C++11以降では関数を int main() { } の代わりに auto main() -> int { } と書ける。テンプレートが絡んだ時に都合の良い事があるらしい。
// 3. C++のmain関数では特例的に返り値をreturnしなくてもデフォルト動作として return 0; がある事になるからもし return 0; で良いならば省略して良い。
auto main() -> int
{
// <iostream>で定義されるC++標準の標準出力にストリーム出力を行う。
// << は実は単なるバイナリーオペレーターで、
// C#
using System;
public class Test
{
public static void Main()
{
var one = 1;
var two = 2;
<?php
$user_input = readline('amidakuji > ');
echo $user_input;
@usagi
usagi / readline_ex.php
Last active August 29, 2015 14:00
readline_ex is readline variation that supports Windows with evil.
function readline_ex( $prompt )
{
switch ( substr( PHP_OS, 0, 3 ) )
{
case 'WIN':
echo $prompt;
file_put_contents('tmp.bat', '@set I='.PHP_EOL.'@set /p I='.PHP_EOL.'@echo %I%');
$user_input = trim( `tmp.bat` );
unlink('tmp.bat');
return $user_input;
@usagi
usagi / add.php
Last active August 29, 2015 14:00
<?php
function add( $params )
{
echo array_reduce( $params, function( $carry, $param ){ return $carry + $param; } ).PHP_EOL;
}
<?php // Reflection example
trait fuga_t
{
public function eee() { echo 'hello eee'.PHP_EOL; }
}
final class hoge_t
{
use fuga_t;