Skip to content

Instantly share code, notes, and snippets.

View JJ's full-sized avatar
🏠
Working from home

Juan Julián Merelo Guervós JJ

🏠
Working from home
View GitHub Profile
@JJ
JJ / cpu-hog.sh
Last active July 1, 2017 07:30
Get the process PID consuming the most CPU
# get the list of PIDs and cpu use, sort numerically using the second column or key, take the last one, and extract the second column
ps —no-headers -eo pid,%cpu | sort -k2 -n | tail -1 | cut -d ' ' -f 2
@JJ
JJ / powers-of-two.py
Created June 29, 2017 16:15
Test for powers of 2 using bitwise operators
print(list(filter( lambda pow2: pow2^(pow2-1) > pow2, range(1000))))
@JJ
JJ / md-to-html.mk
Created May 28, 2017 10:47
Makefile que usa pandoc o markdown-html dependiendo de cuál esté presente
HTML = $(patsubst %.md,%.html,$(wildcard *.md))
all: $(HTML)
$(HTML): %.html: %.md
ifneq ($(shell command -v pandoc 2> /dev/null),)
pandoc $< -o $@
else
ifneq ($(shell command -v markdown-html 2> /dev/null),)
markdown-html $< -o $@
@JJ
JJ / pandoc.mk
Created May 28, 2017 10:37
Convert markdown to HTML with pandoc
HTML = $(patsubst %.md,%.html,$(wildcard *.md))
all: $(HTML)
$(HTML): %.html: %.md
pandoc $< -o $@
@JJ
JJ / substitute-2.mk
Created May 28, 2017 10:27
Substitute extensions in Makefiles
.PHONY = count
HTML = $(patsubst %.md,%.html,$(wildcard *.md))
count: ;@echo $(HTML)
@JJ
JJ / substitute-1.mk
Created May 28, 2017 10:24
Substitute extensions in Makefiles
.PHONY = count
MD = $(wildcard *.md)
HTML = $(MD:.md=.html)
count: ;@echo $(HTML)
@JJ
JJ / wildcard.mk
Created May 28, 2017 10:17
Print files with an extension
.PHONY = count
MAKEFILES = $(wildcard *.mk)
count: ;@echo $(MAKEFILES)
@JJ
JJ / latex.mk
Created March 18, 2017 08:12
Generate latex file
%.pdf: %.tex
pdflatex $<
bibtex $(basename $<)
pdflatex $<
pdflatex $<
@JJ
JJ / spell-n-commit.mk
Created March 18, 2017 08:11
Conditional commit if spelling is correct
.PHONY = commit
status:
-git status -s | grep . && touch status
commit: status
rm status; make -f 3.mk
git commit -am "$(msg)"
@JJ
JJ / hunspell.mk
Created March 18, 2017 08:10
Spell check via makefile
.PHONY: spellcheck
spellcheck:
hunspell -p words.dic -l *.md | grep . && exit 2 || exit 0