Skip to content

Instantly share code, notes, and snippets.

View topecongiro's full-sized avatar
Coffee break

Seiichi Uchida topecongiro

Coffee break
View GitHub Profile
obj-m := hello-module.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
@topecongiro
topecongiro / double_width_compare_and_swap.cpp
Created November 28, 2016 10:59
Double-width compare-and-swap implementation without asm such as CMPXCHG16B.
using u128_t = usigned __int128;
bool dwcas(u128_t* ptr, u128_t oldval, u128_t newval) {
return __sync_bool_compare_and_swap(ptr, oldval, newval);
}
@topecongiro
topecongiro / .latexmkrc
Last active November 30, 2016 14:36
My configuration file for latexmk.
#!/usr/bin/env perl
$latex = 'uplatex -synctex=1';
$latex_silent = 'uplatex -synctex=1 -interaction=batchmode';
$bibtex = 'upbibtex';
$biber = 'biber --bblencoding=utf8 -u -U --output_safechars';
$makeindex = 'mendex %O -o %D %S';
$dvipdf = 'dvipdfmx %O -o %D %S';
$max_repeat = 5;
@topecongiro
topecongiro / stack.rs
Created January 6, 2017 13:25
A simple stack in Rust using Option and Box.
struct Node<T> {
val: T,
next: Option<Box<Node<T>>>,
}
pub struct Stack<T> {
top: Option<Box<Node<T>>>,
}
impl <T>Stack<T> {
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
@topecongiro
topecongiro / install-rustfmt-nightly.sh
Last active December 15, 2017 02:34
Keep rustfmt and clippy up to date
#!/bin/sh
BUILD_DIR=$HOME/.rust-tool-build
# update_tool tool_name tool_binary
update_tool() {
rustup run nightly $2 --version 1>/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
echo "Updating $1"
@topecongiro
topecongiro / setup.sh
Last active January 9, 2018 01:29
Arch Linux setup memo
# Wireless
pacman -S wpa_supplicant
pacman -S dialog # wifi-menu
# Utilities
pacman -S fish
# KDE
pacman -S plasma-meta
@topecongiro
topecongiro / publish.md
Created May 22, 2019 01:37
Steps required to release a new version of rustfmt

1. Update Cargo.toml and Cargo.lock

For example, 1.0.0 -> 1.0.1,

-version = "1.0.0"
+version = "1.0.1"

2. Push the commit to the master branch

@topecongiro
topecongiro / rust_advent_calendar_2019_02.md
Created December 2, 2019 14:37
Rust Advent Calendar 2019 の 2日目の記事

Rust の Deref と DerefMut で継承ができると思わない

Rust でオレオレ文字列型を定義して既存コードに散りばめられた String を置き換えたい気持ちになることがあります。

単純に API を追加して事足りる場合、必要な API をトレイトで定義した上で String に実装すれば十分です:

trait PushNewLine {
    fn push_newline(&mut self);
}