Skip to content

Instantly share code, notes, and snippets.

@misebox
misebox / helper.js
Last active June 9, 2021 09:49
Shorthand function for document.createElement
export default (function(doc) {
function element(elmName, attrs={}) {
const elm = doc.createElement(elmName);
Object.keys(attrs).map(k => elm.setAttribute(k,attrs[k]));
return elm;
}
function divAs(className, attrs={}) {
return element('div', {class: className, ...attrs});
}
return {
@misebox
misebox / usize_bytes.rs
Last active May 23, 2021 18:18
Converting between 64-bit unsigned integer and variable length quantity in rust
// 64bit unsigned integer --> Vec<u8> [4bit, 7bit, 7bit, ..., 7bit]
// from (0b11111111_11111111_..._11111111_11111111)
// to vec![0b1_0001111, 0b1_1111111, ... , 0b1_1111111, 0b0_1111111]
pub fn usize_to_bytes(val: usize) -> Vec<u8> {
let mut v: Vec<u8> = vec![];
let mut n = val;
loop {
let b = (n & 0x7fusize) as u8;
n >>= 7;
if v.is_empty() {
@misebox
misebox / atom_names.txt
Last active April 4, 2021 02:13
Atom names
1.Hydrogen 2.Helium
3.Lithium 4.Beryllium 5.Boron 6.Carbon 7.Nitrogen 8.Oxygen 9.Fluorine 10.Neon
11.Sodium 12.Magnesium 13.Aluminium 14.Silicon 15.Phosphorus 16.Sulfur 17.Chlorine 18.Argon
19.Potassium 20.Calcium 21.Scandium 22.Titanium 23.Vanadium 24.Chromium 25.Manganese 26.Iron 27.Cobalt 28.Nickel 29.Copper 30.Zinc 31.Gallium 32.Germanium 33.Arsenic 34.Selenium 35.Bromine 36.Krypton
37.Rubidium 38.Strontium 39.Yttrium 40.Zirconium 41.Niobium 42.Molybdenum 43.Technetium 44.Ruthenium 45.Rhodium 46.Palladium 47.Silver 48.Cadmium 49.Indium 50.Tin 51.Antimony 52.Tellurium 53.Iodine 54.Xenon
55.Caesium 56.Barium Lanthanoid 57.Lanthanum 58.Cerium 59.Praseodymium 60.Neodymium 61.Promethium 62.Samarium 63.Europium 64.Gadolinium 65.Terbium 66.Dysprosium 67.Holmium 68.Erbium 69.Thulium 70.Ytterbium 71.Lutetium 72.Hafnium 73.Tantalum 74.Tungsten 75.Rhenium 76.Osmium 77.Iridium 78.Platinum 79.Gold 80.Mercury 81.Thallium 82.Lead 83.Bismuth 84.Polonium 85.Astatine 86.Radon
87.Francium 88.Radium Actinoid 89.Actinium 90.T
@misebox
misebox / deepgrep
Last active February 17, 2021 06:31
対象ファイル(またはディレクトリ)のgitの履歴の中から指定されたパターンを探す。
#!/bin/bash
if [ $# -lt 2 ]
then
echo "Usage: `basename $0` <pattern> <single-target-path>"
echo
exit
fi
pattern="$1"
filename="$2"
@misebox
misebox / Dockerfile
Created November 14, 2020 08:10
Dockerfile and docker-compose.yml for ruby2.2.3
FROM centos:6.6
RUN yum update -y && yum install -y tar which \
&& curl -sSL https://rvm.io/mpapis.asc | gpg --import - \
&& curl -sSL https://rvm.io/pkuczynski.asc | gpg --import - \
&& curl -sSL https://get.rvm.io | bash -s stable
RUN ["/bin/bash", "-c", "-l", "rvm install 2.2.3"]
ENV PATH $PATH:/usr/local/rvm/rubies/ruby-2.2.3/bin
WORKDIR /app
CMD irb
@misebox
misebox / plantuml-png.sh
Created August 26, 2020 10:09
Generate png with plantUML
#!/bin/bash
if [ "$1" = "" ] || [ ! -f "$1" ]
then
echo "Filename is required"
exit 1
fi
src_name="$1"
png_name=${src_name%.*}.png
cid=`docker run -d -p 8080:8080 plantuml/plantuml-server:jetty-v1.2020.14 | head -n1`
@misebox
misebox / tetrominoes.js
Created July 27, 2020 03:07
Oneliner making tetrominoes in Javascript
0xf0cc6cc68e2e4en.toString(16).match(/../g).map(a => (a.split('').map(b =>([8,4,2,1].map(c =>(parseInt(b,16)&c)?'#':' ').join('')))))
[alias]
co = checkout
ci = commit
st = status
br = branch
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
l = log --oneline --decorate --graph --date=short
type = cat-file -t
dump = cat-file -p
[core]
@misebox
misebox / settings.json
Last active March 16, 2022 18:23
VSCode minimal settings.json.
{
// Instead of turning this off, use the key binding [CTRL+k Enter] to change an editor in preview mode into edit mode.
"workbench.editor.enablePreview": true,
// Useful suggestion
"editor.quickSuggestions": true,
"editor.suggest.statusBar.visible": true,
"editor.suggest.localityBonus": true,
"editor.suggest.showKeywords": true,
@misebox
misebox / keybindings.json
Last active June 1, 2020 10:18
VSCode minimal KeyBindings for vim extension on linux user.
[
// Side bar is toggled with [CTRL + SHIFT + B]
{
"key": "ctrl+shift+b",
"when": "sideBarVisible",
"command": "workbench.action.closeSidebar"
},
{
"key": "ctrl+shift+b",
"when": "!sideBarVisible",