Skip to content

Instantly share code, notes, and snippets.

View martinhj's full-sized avatar
🏴‍☠️

Martin Holt Juliussen martinhj

🏴‍☠️
View GitHub Profile
@martinhj
martinhj / javascript-regex.js
Created April 4, 2019 13:11
Javascript lookahead & -behind
// positive lookahead
// ?=
const lookaheadRegex = /something(?=\$)/ // match something at end of line, but not the end of line
// positive lookbehind
// ?<=
const lookaheadRegex = /(?<=\^)something/ // match something at the start of line, but not the start of line
// negative lookahead
// ?!
@martinhj
martinhj / createAndFillArray.js
Last active April 2, 2019 07:02
Create and fill array of given size
// create and fill array of given size
const arrayWithNumbers = Array(4).fill(null).map((u, i) => i) [0, 1, 2, 3]
// or
const newArrayWithNumbers = [...Array(4)].map((u, i) => i)
@martinhj
martinhj / for.sh
Created March 25, 2019 19:19
rerun command stored in env variable
# EXPORT COMMAND FIRST
export COMMAND="dd if=/dev/urandom of=secret.tar.bz2 bs=56724259 count=1 conv=notrunc"
# THEN
for ((n=1;n<8;n++)); do eval $COMMAND; done;
@martinhj
martinhj / bulk-rename.md
Created March 12, 2019 08:15
Bulk rename bash
for file in src/file/path/images/common-name-*
  do
    git mv $file $(echo $file| sed 's/\(.*\)common-name.*/\1/')other-common-name$(echo $file | sed 's/.*common-name\(.*\)/\1/')
  done
@martinhj
martinhj / projectSpecificVimrc.md
Last active October 23, 2017 20:34
vim and project specific config

vim and project specific config

I've been in a few .php/.js-projects lately where it is not straight forward to use gf ("goto file"). Usually when the cursor in vim is above a filename I simply hit gf and it opens that file for reviewing/editing.

But in webdev land where I have been lately it is not untypically to do a reference to a file of sorts:
{% include '\_partials/main-menu' with {id: mainMenu} %}

It states the path _partials/main-menu, but the file that I want to investigate is craft/templates/_partials/main-menu.twig.

To gf my way to the right file I found that I could set path+=$PWD/craft/templates and set suffixesadd+=.twig