Skip to content

Instantly share code, notes, and snippets.

View kosugi's full-sized avatar

KOSUGI Tomo kosugi

  • tokyo.japan
View GitHub Profile
# coding: utf-8
def fact(n); (n==1)? 1: n*fact(n-1); end;
class Fixnum; def !(); fact(self); end; end
print 3.!.!.!
// semicolonless Java
public class A
{
public static void main(String[] args) {
return\u003b
}
}
// clang -Wall -x objective-c -std=c99 -fobjc-arc -framework Foundation -o a.out a.m
#import <objc/objc.h>
#import <objc/objc-runtime.h>
#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
void foo(int a)
{
switch (a)
{
@kosugi
kosugi / add-include-path.rb
Created July 21, 2014 10:39
add include path
# -*- coding: utf-8 -*-
path = File.expand_path File.join File.dirname(__FILE__), '..', 'lib'
$LOAD_PATH.unshift path unless $LOAD_PATH.include? path
(defun new-working-buffer ()
(interactive)
(find-file (concat
(format-time-string "~/%Y-%m%d-%H%M%S.")
system-name)))
// g++ -std=c++11 RiverCrossing.cpp
#include <iostream>
#include <queue>
#include <vector>
#include <array>
#include <algorithm>
using namespace std;
@kosugi
kosugi / angle.py
Last active August 29, 2015 13:56
from math import pi, sqrt, acos, asin, sin, cos
for n in range(0, 360+1, 10):
x = cos(pi * n / 180)
y = sin(pi * n / 180)
r = sqrt(x ** 2 + y ** 2)
th_cos = 180 * acos(x / r) / pi
th_sin = asin(y / r)
if th_sin < 0:
th_cos = 360 - th_cos
from math import pi, sqrt, acos, asin
def vsub(a, b):
return (a[0] - b[0], a[1] - b[1])
def hit(a, b, c, p):
ab = vsub(b, a)
bp = vsub(p, b)
bc = vsub(c, b)
cp = vsub(p, c)
# -*- coding: utf-8 -*-
# http://www.checkio.org/mission/brackets/
# 普通こうでは!?
from itertools import dropwhile
pairs = '{} [] ()'.split()
def parse_term(s):
t = ''.join(dropwhile(str.isdigit, s))
@kosugi
kosugi / with-short-circuiting.el
Last active December 31, 2015 17:29
マクロに apply できない問題
(defun or/l (args)
(let ((r nil))
(while (and args (null r))
(setq r (or r (car args)))
(setq args (cdr args)))
r))