Skip to content

Instantly share code, notes, and snippets.

View ryohji's full-sized avatar

Ryohji Ikebe ryohji

  • Tokyo, Japan
View GitHub Profile
1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11月 12月
1 32 60 91 121 152 182 213 244 274 305 335
2 33 61 92 122 153 183 214 245 275 306 336
3 34 62 93 123 154 184 215 246 276 307 337
4 35 63 94 124 155 185 216 247 277 308 338
5 36 64 95 125 156 186 217 248 278 309 339
6 37 65 96 126 157 187 218 249 279 310 340
7 38 66 97 127 158 188 219 250 280 311 341
8 39 67 98 128 159 189 220 251 281 312 342
@ryohji
ryohji / update_all_elements_in_vector.cc
Created January 21, 2022 16:33
Use transform(map) function to modify the elements in a container. [C++]
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
int main() {
auto v = std::vector<int> {1, 2, 3};
// Use transform to update all elements in the vector.
std::transform(std::cbegin(v), std::cend(v), std::begin(v),
@ryohji
ryohji / cleanup_list.py
Last active August 9, 2021 06:50
リストから不要な要素を取りのぞく方法
import unittest
def cleanup_list(list):
i = 0
while i < len(list): # pop のたびに list 長が変わる
elem = list[i]
if not elem.alive:
list.pop(i)
else:
@ryohji
ryohji / roff.c
Last active February 10, 2021 17:14
umoria roff
static vtype roffbuf; // Line buffer.
static char *roffp = roffbuf; // Pointer into line buffer.
static int roffpline = 0; // Place to print line now being loaded.
static uint8_t count_previous_non_blank_chars(const char *from);
// Print out strings, filling up lines as we go.
static void roff(const char *p) {
uint8_t count;
loop:
@ryohji
ryohji / not.md
Last active November 7, 2020 06:54
not operator in C

C 言語の not 演算子には2種類ある。 ~!。論理学では ~ を否定で使うことが多いけれど C 言語での論理否定は !~ はビットごとの否定。

ビットごとの否定

// bitwise-not.c
#include <stdbool.h>

int main() { return ~false; }
@ryohji
ryohji / gist:8a54bb046555d703a316d418203ce401
Created May 2, 2020 18:25
(A ⇒ B) ∧ (¬A ⇒ C) = (A ∧ B) ∨ (¬A ∧ C)
(A ⇒ B) ∧ (¬A ⇒ C)
=
(¬A ∨ B) ∧ (¬¬A ∨ C)
=
(¬A ∨ B) ∧ (A ∨ C)
=
((¬A ∨ B) ∧ A) ∨ ((¬A ∨ B) ∧ C)
=
((¬A ∧ A) ∨ (B ∧ A)) ∨ ((¬A ∧ C) ∨ (B ∧ C))
=
@ryohji
ryohji / apparent-gibberish.md
Last active April 25, 2020 17:43
Make sense of the apparent gibberish in “A Logical Approach to Discrete Math” Ch.0

Every value in array segment b[1..n] that is not in b[i..j] is in b[i..j].

Let predicate p(v) be "v is in b[i..j]."

  (A k: 0<k<=N: ~p(b[k]) -> p(b[k]))
=
  (A k: 0<k<=N: ~~p(b[k]) | p(b[k]))
=
 (A k: 0
@ryohji
ryohji / EqLogic.g4
Created April 18, 2020 14:04
Equational logic syntax
grammar EqLogic;
predicate
: predicate substitution
| LPAREN predicate RPAREN
| BOOLEAN
| ID
| NOT predicate
| predicate IMPLY predicate
| predicate AND predicate
interface Substitution {
fun with(vararg ps: Predicate): Predicate
}
interface Predicate {
fun substitute(vararg xs: Symbol): Substitution
}
data class Symbol(val name: String) : Predicate {
override fun toString(): String = name
@ryohji
ryohji / ImageProcessing.kt
Created December 13, 2019 08:59
2 dimensional image processing (filter)
object ImageProcessing {
fun smoothing(stride: Int, buffer: ByteArray): ByteArray =
buffer.toIntList()
.convolution(stride)
.map { (it / 9).toByte() }
.toByteArray()
fun sharpen(stride: Int, buffer: ByteArray): ByteArray =
buffer.toIntList()