Skip to content

Instantly share code, notes, and snippets.

@alpha22jp
alpha22jp / aes_test.cpp
Created July 16, 2018 05:41
OpenSSL AES暗号・復号化のサンプル
// gcc aes_test.cpp -lcrypto
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <openssl/evp.h>
#include <openssl/aes.h>
void print_bytes(const uint8_t *bytes, const size_t len)
{
@alpha22jp
alpha22jp / deferred-loop-sample.el
Last active November 26, 2016 05:50
deferredを使った繰り返し処理のサンプル
;;; deferred-loop-sample.el --- deferredを使った繰り返し処理のサンプル
;;; Commentary:
;; ~/tmp/に1.txt ~ 40.txtを作成する。(~/tmp/をあらかじめ作っておくこと)
;; deferred:parallelで並列処理するが、一度に作れるプロセスに上限があるため、
;; 16個ずつに区切って繰り返し (deferredの再帰) で実行する。
;;; Code:
@alpha22jp
alpha22jp / wripe_to_simplenote.rb
Last active November 20, 2016 02:21
wri.peからexportしたノートをSimplenoteに登録
#!/usr/bin/env ruby
# coding: utf-8
#-------------------------------------------------------------------------------
# wripe_to_simplenote.rb
# wri.peからexportしたノートをsimplenoteに登録する
#-------------------------------------------------------------------------------
require './simplenote'
email = 'abc@exmaple.com'
password = 'password'
@alpha22jp
alpha22jp / dump-string.el
Created October 22, 2016 03:00
Dump string as a byte sequence
(defun dump-string (str)
(let ((i 0) ret)
(when (stringp str)
(while (< i (length str))
(setq ret (if ret
(format "%s %x" ret (aref str i))
(format "%x" (aref str i))))
(setq i (1+ i))))
ret))
@alpha22jp
alpha22jp / Makefile
Created October 20, 2016 01:38
MakefileでAND/OR条件判定
COND_A = NO
COND_B = YES
all:
# AND condition
ifeq ($(COND_A) $(COND_B), YES YES)
@echo "A and B is true"
else
@echo "A and B is false"
endif
@alpha22jp
alpha22jp / init_for_c++11_coding.el
Last active October 28, 2018 10:46
Emacs settings for C++11 coding
;;; init_for_c++11_coding.el --- Emacs settings for C++11 coding
;; Copyright (C) 2015 alpha22jp
;; Author: alpha22jp <alpha22jp@gmail.com>
;; Keywords: C++11
;;; Commentary:
;;; Install yasnippet, company, irony, flycheck-irony and rtags from MELPA
@alpha22jp
alpha22jp / myclass_iterator.cpp
Created December 26, 2015 13:26
自作クラスに対するイテレータの実装サンプル
// Copyright (C) 2015 alpha22jp@gmail.com
//
#include <iostream>
#include <memory>
#include <string>
#include <unordered_map>
class IntObject {
public:
explicit IntObject(int val) : m_val(val) {}
@alpha22jp
alpha22jp / PuyoPuyo.hs
Last active November 20, 2016 12:41
Haskell版ぷよぷよ
import Control.Lens
import Control.Monad.State
import Data.List
type Point = (Int, Int)
type Board = [[Char]]
rowNum = 13 :: Int
colNum = 6 :: Int
@alpha22jp
alpha22jp / SafeAction.hs
Last active November 20, 2016 12:43
Haskell例外捕捉のサンプル
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Exception
import Control.Monad.Trans.Error
import Control.Monad.IO.Class
import System.IO.Error
-- IO例外のみ捕捉できる
safeIOAction :: IO a -> ErrorT String IO a
safeIOAction action = do
@alpha22jp
alpha22jp / HTTPTest.hs
Created June 27, 2015 13:16
HTTP client sample for Haskell
{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP hiding (urlEncode)
import Network.URI
import Data.Maybe
import Data.ByteString.Char8 as BS
import Data.ByteString.Base64 (encode)
token :: String -> String -> BS.ByteString
token email pass = encode . BS.pack $ urlEncodeVars [("email", email), ("password", pass)]