Skip to content

Instantly share code, notes, and snippets.

@ryo1kato
ryo1kato / gist:141c3e6407da5a552a4433474fdbcc14
Created February 19, 2023 22:13
Keyboardio Atreus keymap 2022-02-19
{
"keymaps": [
[
{"code": 20, "label": {"base": "q", "shifted": "Q"}},
{"code": 26, "label": {"base": "w", "shifted": "W"}},
{"code": 8, "label": {"base": "e", "shifted": "E"}},
{"code": 21, "label": {"base": "r", "shifted": "R"}},
{"code": 23, "label": {"base": "t", "shifted": "T"}},
{
"code": 0,
import collections
class Multiset(collections.Counter):
def add(self, elem):
self[elem] += 1
def remove(self, elem):
self[elem] -= 1
if self[elem] == 0:
del self[elem]
@ryo1kato
ryo1kato / p
Created December 20, 2020 17:03
color pager
#!/bin/bash
# color pager
# run command with appropriate color option (like --color-output for 'jq') and pipe to a pager
if which lv >/dev/null 2>&1
then
pager=(lv -c)
else
pager=(less -R)
fi
// https://leetcode.com/problems/median-of-two-sorted-arrays/description/
package main
import (
"fmt"
"math/rand"
"runtime"
"sort"
"time"
)
@ryo1kato
ryo1kato / right-light.sh
Created March 16, 2019 17:39
right and light
#!/bin/bash
set -ue
voices=($(say -v '?' | egrep 'en_US|en_UK' | egrep -v 'Pipe Organ|Bubbles|Bells|Bahh|Hysterical|Boing|Bad|Albert'| awk '{print $1}'))
nr_voices=${#voices[@]}
correct=0
wrong=0
RANDMAX=32767
with open("filename.txt") as f:
lineIdx = 0
for line in f:
if lineNo %2 == 1:
print(lastline + "の" + line)
else:
lastline = line
lineIdx += 1
// https://leetcode.com/problems/n-queens-ii
func totalNQueens(n int) int {
ans := []int{0,1,0,0,2,10,4,40,92,352,724,2680,14200,73712,365596,2279184,14772512,95815104,666090624,4968057848,39029188884,314666222712,2691008701644,24233937684440,227514171973736,2207893435808352,22317699616364044,234907967154122528}
return ans[n]
}
import sys, os, re
class AutoLoader():
def __init__(self, nickname, modulename):
self.nickname = nickname
self.modulename = modulename
def __getattr__(self, methodname):
g = globals()
g[self.nickname] = __import__(self.modulename)
@ryo1kato
ryo1kato / lab2.cpp
Last active November 4, 2017 04:12
Kei's lab
//This is lab2 the vending machine creat by Kei Kato.
#include <iostream>
#include <iomanip>
#include <cstdlib>
#define PLURAL(variable, word) \
variable << word << (variable > 1 ? "s" : "")
using namespace std;
int analogReadPS(uint8_t pin) {
ACSR &= ~ _BV(ACD); // Enablethe analog comparator
bitClear(PRR, PRADC); // power up ADC
ADCSRA |= _BV(ADEN);
unsigned int reading = analogRead(pin);
ADCSRA &= ~_BV(ADEN);
bitSet(PRR, PRADC); // power down ADC
ACSR |= _BV(ACD); //Disable the analog comparator