Skip to content

Instantly share code, notes, and snippets.

View proboscis's full-sized avatar

Proboscis proboscis

View GitHub Profile
@proboscis
proboscis / example.py
Last active October 19, 2023 06:33
An example of generating function spec for openai API using LLM and prompt
from pydantic import BaseModel
class ParameterProperty(BaseModel):
type: str # must be either 'string' or 'number'
description: str
class FunctionParameters(BaseModel):
type: str # must be 'object'
@dataclass
class ActorRefRemoteEnv(IRemoteEnv):
remote_env: ActorHandle
remote_env_refs: ActorHandle = field(default=None)
remote_env_id: ObjectRef = field(default=None)
def __post_init__(self):
if self.remote_env_id is None:
self.remote_env_id = self.remote_env.get_env_id.remote()
@proboscis
proboscis / main.cpp
Last active August 29, 2015 14:20
Performance Comparison
#include "stdio.h"
#include "time.h"
#include <functional>
class V3{
public:
V3(){}
V3(float a,float b,float c):x(a),y(b),z(c){}
float x;
float y;
float z;
#define news(T,...) std::shared_ptr<T>(new T(__VA_ARGS__))
auto splitBox(const Objects& objs,const BBox& box){
//通った!
return news(TwoBox,news(BBox,box.min,vmax),news(BBox,vmin,box.max));
}
//1.流石にshared_ptrは省略するとして
template <typename T> using sptr = std::shared_ptr<T>;
//typedefなし
sptr<std::pair<sptr<BBox>, sptr<BBox>>> splitBox(const Objects& objs,const BBox& box){
//いろいろする
return sptr<std::pair<sptr<BBox>,sptr<BBox>>>(new std::pair<sptr<BBox>,sptr<BBox>>(sptr<BBox>(new BBox(box.min,vmax)),sptr<BBox>(new BBox(vmin,box.max))));
}
//2.typedefあり
using A = std::pair<sptr<BBox>,sptr<BBox>>;
@proboscis
proboscis / Calendar.sc
Last active August 29, 2015 14:18
使い方:%scala Calendar.sc < input.txt > gcal.csv
import java.text.SimpleDateFormat
import java.util.Date
import java.util.concurrent.TimeUnit
import scala.util.{Success, Try}
val lines = Iterator.continually(readLine()).takeWhile(_!=null)
val dateFormat = new SimpleDateFormat("""MM/dd/yy""")
val timeFormat = new SimpleDateFormat("""HH:mm:ss""")
def lineToCol(str:String):Try[String] = Try{
str.split('|') match {
@proboscis
proboscis / MakeNSolver.scala
Last active August 29, 2015 14:10
MakeNSolver! usage:"%scala MakeNSolver.scala". Change the last line to test with other parameters
object MakeNSolver {
import scala.util.{Success, Try}
trait Expr
case class Number(value: Int) extends Expr
case class BinOp(op: String, l: Expr, r: Expr) extends Expr
val binOps: Map[String, (Int, Int) => Int] = Map(
"*" -> (_ * _),
"/" -> (_ / _),
"+" -> (_ + _),
"-" -> (_ - _))
@proboscis
proboscis / GameEventManager
Last active August 29, 2015 14:07
GameEventManager
using UnityEngine;
using System.Collections.Generic;
using System;
public delegate void GameEventDelegate<T>(T e);
public class EventManager : MonoBehaviour {
//I want to omit the type parameters on the right-hand side... like " = new Dictionary()";
private GameEventDelegate<System.Object> dummy = new GameEventDelegate<System.Object>();
private Dictionary<System.Type,GameEventDelegate<Object>> listeners = new Dictionary<GameEventDelegate<Object>>();
public void addListener<T>(GameEventDelegate<T> f){
@proboscis
proboscis / AutoSave.cs
Last active August 29, 2015 14:07 — forked from tsubaki/AutoSave.cs
using System.Collections;
using UnityEditor;
using UnityEngine;
using System.IO;
[InitializeOnLoad]
public class AutoSave
{
public static readonly string manualSaveKey = "autosave@manualSave";
@proboscis
proboscis / gist:9015172
Created February 15, 2014 06:05
implicitly retrieves an instance of Class[T] without allocatio
import scala.language.experimental.macros
import scala.reflect.macros.Context
trait ClassMacro{
/**
* implicitly returns a class of specified type!
**/
implicit def getClassMacro[T]:Class[T] = macro ClassMacroImpl.getClassMacroImpl[T]
}
object ClassMacroImpl{