Skip to content

Instantly share code, notes, and snippets.

@snipsnipsnip
snipsnipsnip / schtasks.rb
Last active August 24, 2019 15:33
ramen timer using windows schtasks command
class SchTasks
def initialize(password = nil)
@password = password
end
def include?(taskname)
schtasks('/query', '/nh') do |f|
f.read =~ /^#{taskname}/
end
end
@snipsnipsnip
snipsnipsnip / shortcmd.bat
Last active August 24, 2019 15:17
starts windows cmd in short path (requires ruby)
@ruby -x "%~f0" %*
@exit /b
#!ruby -Ks
require 'Win32API'
GetShortPathName = Win32API.new('kernel32', 'GetShortPathName', 'ppi', 'i')
def get_short_path_name(path)
len = GetShortPathName.call(path, nil, 0)
@snipsnipsnip
snipsnipsnip / PauseMonad.hs
Last active August 24, 2019 15:18
Pause Monad
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, UndecidableInstances #-}
module PauseMonad
( MonadPause (..)
, Pause (..)
, PauseT (..)
, tracePauseT
, module Control.Monad.Trans
) where
@snipsnipsnip
snipsnipsnip / YieldMonad.hs
Last active August 24, 2019 15:24
Yield monad
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, UndecidableInstances, FunctionalDependencies #-}
module YieldMonad
( MonadYield (..)
, Yield (..)
, YieldT (..)
, traceYieldT
, module Control.Monad.Trans
) where
@snipsnipsnip
snipsnipsnip / Var.hs
Last active August 24, 2019 15:24
Variable in monad
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, UndecidableInstances, FunctionalDependencies #-}
module Var
( MonadVar (..)
, module Control.Monad.Trans
) where
import Control.Monad.Error
import Control.Monad.State
import Control.Monad.Reader
@snipsnipsnip
snipsnipsnip / .bashrc
Last active August 24, 2019 15:25
bashrc, inputrc, nethackrc, screenrc, vimrc
export PATH=~/bin:$PATH
export LANG=ja_JP.UTF-8
PS1="\\t \[\e[32m\]\\w\[\e[\$((\$? ? 33 : 36))m\]> \[\e[0m\]"
complete -d cd
complete -c man
alias rm='rm -i'
alias ..='cd ..'
alias l='ls -l'
@snipsnipsnip
snipsnipsnip / ApplicativeUtil.hs
Last active August 24, 2019 15:25
Control.Monad stuff in Applicative
import Control.Applicative
-- Control.Monad stuff in Applicative
-- Data.Traversable has generalized version
mapA :: Applicative f => (a -> f b) -> [a] -> f [b]
mapA f xs = sequenceA (map f xs)
mapA_ :: Applicative f => (a -> f b) -> [a] -> f ()
mapA_ f xs = sequenceA_ (map f xs)
@snipsnipsnip
snipsnipsnip / va.hs
Last active August 24, 2019 15:25
instance Num Vector2の実装を簡単に
import Control.Applicative
data Vector2 a = Vector2 a a deriving (Show, Eq)
instance Applicative Vector2 where
pure x = Vector2 x x
Vector2 fx fy <*> Vector2 x y = Vector2 (fx x) (fy y)
instance Functor Vector2 where
fmap = liftA
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#ifndef ungetchar
#define ungetchar(c) ungetc((c), stdin)
#endif
typedef struct tree Tree;
@snipsnipsnip
snipsnipsnip / debug.h
Last active August 24, 2019 15:34 — forked from takuma104/spherical_panorama_sample.rb
spherical_panorama_sample.c
#ifndef DEBUG_H_
#define DEBUG_H_
#ifdef _MSC_VER
# define DEBUG_H_FUNCTION_NAME __FUNCTION__
#else
# define DEBUG_H_FUNCTION_NAME __func__
#endif
#define PrintInfoFormatIntlIntl(p,line) \