Skip to content

Instantly share code, notes, and snippets.

Avatar

Yuya Kono takoeight0821

View GitHub Profile
@takoeight0821
takoeight0821 / bf2c.sh
Last active May 17, 2020
Brainf**kコンパイラ。BFからCへのコンパイラと、gccに食わせると定数に最適化されることを示すデモ。#hiro_it 用
View bf2c.sh
echo '#include <stdio.h>'
echo 'int main(void) {'
echo 'int tape[256] = {0};'
echo 'int i = 0;'
cat $@ |\
sed -e 's/\]/}/g' |\
sed -e 's/\[/while(tape\[i\]){/g' |\
sed -e 's/+/tape\[i\]++;/g' |\
sed -e 's/-/tape\[i\]--;/g' |\
sed -e 's/>/i++;/g' |\
@takoeight0821
takoeight0821 / Main.scala
Created Mar 17, 2020
Scalaを思い出すために書いたミニミニLisp
View Main.scala
// libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2"
import scala.util.parsing.combinator._
import scala.collection.mutable._
sealed trait SExpr
case class Symbol(x: String) extends SExpr
case class IntLiteral(x: Int) extends SExpr
case class SList(xs: List[SExpr]) extends SExpr
sealed trait SValue
We couldn’t find that file to show.
@takoeight0821
takoeight0821 / GIf.hs
Last active Dec 2, 2019
generic 'if'
View GIf.hs
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module GIf where
import Data.Kind
import GHC.Generics
import Prelude
@takoeight0821
takoeight0821 / Main.hs
Last active Nov 3, 2019
エキゾチックなNumインスタンス
View Main.hs
module Main where
newtype IODouble = IODouble { runIODouble :: IO Double }
instance Num IODouble where
fromInteger x = IODouble $ do
print x
pure $ fromInteger x
(IODouble x) + (IODouble y) = IODouble $ do
x' <- x
@takoeight0821
takoeight0821 / foo.s
Created Aug 31, 2019
Arch Linuxでclang -c foo.sでこれコンパイルするとclangがセグフォする
View foo.s
.intel_syntax noprefix
.text
not:
ret
f:
call not
ret
# 以下ログ
# Stack dump:
@takoeight0821
takoeight0821 / main.c
Last active Apr 16, 2019
zamの実装っぽい何か
View main.c
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <gc.h>
#include <stdint.h>
struct value;
struct env
{
@takoeight0821
takoeight0821 / main.c
Last active Apr 13, 2019
スタックマシンっぽい何か
View main.c
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <gc.h>
union value;
struct env;
struct closure;
union value;
@takoeight0821
takoeight0821 / main.js
Last active Feb 5, 2019
ダブルクロス対応のダイスbot
View main.js
const Discord = require('discord.js');
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
}
function diceRoll(count, roll) {
let dices = [];
@takoeight0821
takoeight0821 / main.cc
Last active Dec 11, 2018
競プロの簡単な問題を解いたときの副産物
View main.cc
#include <iostream>
#include <tuple>
#include <algorithm>
#include <vector>
using namespace std;
template <typename T>
unsigned int digit_sum(T x, unsigned int base) {
auto result = 0;
You can’t perform that action at this time.