Stuff I might need again... and will probably forget
Symbolic link to another file
ln -s /path/to/file /path/to/symlink
Initiate a new npm project without having to specify anything
npm init -y
Single file ls | grep -v <file> | xargs -L 1 rm -rf
Multiple files ls | grep -v -e <first file> -e <second file> | xargs -L 1 rm -rf
ls | grep -v -e <file> -e <folder> | while read x; do mv $x ./<folder>/$x; done
A strange artifact is created with OpenVZ, so lets remove it rm -rf .cpt_hardlink_dir_*
find . -not -path '*/\.*' | python -c "import sys as s;s.a=[];[setattr(s,'a',list(filter(lambda p: c.startswith(p+'/'),s.a)))or (s.stdout.write(' '*len(s.a)+c[len(s.a[-1])+1 if s.a else 0:])or True) and s.a.append(c[:-1]) for c in s.stdin]"
printenv | less
lsof -i <protocol>:<port>
For example to check what is using TCP port 80
lsof -i TCP:80
ps -p <PID> -o comm=
Using cat
, cat -n <file>
Using less
, less -N <file>
This is a really cool command, it allows you to watch a command and listen for changes.
For example sometihng as simple as watching the response from an API end point
watch -d curl -s localhost:3000
where the -s
option just removes the status bar (aka silent).
DNS - less /etc/resolv.conf
GW - less /etc/network/interfaces
pip install <package>==<version>
For example - pip install ansible==2.1.0
GUI method - nmtui
First find the drive
OSX - diskutil list
Linux - lsblk
Now unmount the drive umount /dev/disk
Now copy the image to the disk with dd
dd bs=1m if=<input image> of=<output disk>
To provide process while dd
is copying, you can either press ctrl + T
or you can use pv
(Pipe Viewer).
Now you can run dd
like this: where -s specified the file size to provide a completion bar.
dd if=/dev/sdb | pv -s 2G | dd of=DriveCopy1.dd bs=4096
tcpdump -nni <interface> port <port>
For example - tcpdump -nni eth0 port 80
cat ~/.ssh/id_rsa.pub | ssh <user>@<host> "cat >> ~/.ssh/authorized_keys"
You can also just use ssh-copy-id <user>@<host>
, however, this isn't always installed.
VBoxManage list runningvms | cut -d \" -f2 | while read key; do echo `vboxmanage controlvm ${key} poweroff && vboxmanage unregistervm ${key} --delete`; done && vagrant global-status --prune
This only currently will work if the box is running
Requirements:
- p7zip-full
- mkisofs
Process:
- Move the ISO into a new folder for extraction (I used
/tmp/iso
) - Extract the ISOs contents
7z x <image>.iso
- Deleted the ISO
rm <image>.iso
- Make your changes
- Repack the ISO
mkisofs -o <output name>.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V "CentOS 7.0 Custom ISO" .
nmap -T5 -sP <ip start range>-<ip end range>
For example - nmap -T5 -sP 172.20.60.0-255
Got a new git repo? Did you accidently commit all the .DS_Store
files in your project?
Here's a simple remedy:
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch && echo ".DS_Store" >> .gitignore
extension_id=<id>
curl -L -o "$extension_id.zip" "https://clients2.google.com/service/update2/crx?response=redirect&os=mac&arch=x86-64&nacl_arch=x86-64&prod=chromecrx&prodchannel=stable&prodversion=44.0.2403.130&x=id%3D$extension_id%26uc"
unzip -d "$extension_id-source" "$extension_id.zip"
const $ = (selector) => document.querySelector(selector)
const $$ = (selector) => document.querySelectorAll(selector)
const on = (elem, type, listener) => elem.addEventListener(type,listener)
# create pem public key if you don't have one
openssl rsa -in ~/.ssh/<your private rsa key> -pubout > ~/.ssh/<name>.pem
# encrypt the text
echo "text" | openssl rsautl -encrypt -pubin -inkey <public key>.pem > <cypher file>
# decrypt the cypher
openssl rsautl -decrypt -inkey ~/.ssh/<your private rsa key> -in <cypher file>
.heading {
flex: 1 1 auto;
height: 4rem;
&, & > * {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
fold -w 64
First locate the .m3u8
file in the network.
Install ffmpeg
Run ffmpeg -protocol_whitelist file,http,https,tcp,tls,crypto -i "https//file.com/viedo.m3u8" -c copy video.mp4
const interpolate = (str, data) => str.replace(/\{(.*?)\}/g, (_, token) => data[token]);
interpolate(
'{name} said {message}',
{
name: 'Dane',
message: 'Hello, World!'
}
);
When you first start a project, project stucture tends to change a lot. If you want to merge a feature branch into master, and take all of the new changes and leave the old ones behind do this.
git checkout feature_branch
git merge -s ours --no-commit master
git commit -m "..."
git checkout master
git merge feature_branch
Instead of depending on a URL to always host an image, this utility will replace all markdown images and inline them as JPEGs.
const sharp = require('sharp');
const fetch = require('node-fetch');
const transformImage = url => {
return fetch(url)
.then(response => response.buffer())
.then(buffer => sharp(buffer)
.resize({
width: 600,
})
.toFormat('jpeg')
.toBuffer()
)
.then(buffer => buffer.toString("base64"));
};
const replaceAsync = async str => {
const rx = /!\[(.*?)\]\((.*?)\)/g;
const promises = [];
str.replace(rx, (_, name, url) => {
const promise = transformImage(url)
.then(data => `![${name}](data:image/jpeg;base64,${data})`);
promises.push(promise);
});
const data = await Promise.all(promises);
return str.replace(rx, () => data.shift());
};
const nodes = document.body.querySelectorAll('*');
let styles = [];
Array.from(nodes).forEach(node => {
const computedStyles = window.getComputedStyle(node);
// if (/(<font-name>|<font-name>)/.test(computedStyles['font-family'])) {
styles.push({
family: computedStyles['font-family'].split('"')[1],
weight: computedStyles['font-weight'],
style: computedStyles['font-style'],
});
//}
});
stylesEqual = (current, next) => (
current.family === next.family &&
current.weight === next.weight &&
current.style === next.style
);
styles = styles.reduce((acc, curr) => {
if (acc.some(next => stylesEqual(next, curr))) return acc;
return [ ...acc, curr ];
}, []);
While developing with Lerna I found it valuable to use Verdaccio to test publishing of packages. Lerna also pushes a bunch of tags to origin which I wanted to avoid so I didn't have to rebase master and delete tags each time.
Git allows different type of remotes, including a repository on your local machine, here's how to set it up:
# Get your current origin
git remote -v
# Create a temporary repo
mkdir -p ~/tmp/local
cd ~/tmp/local
git init
# Add new origin
git remote set-url origin ~/tmp/local
git push -u origin master
Now you can use the local repository as a remote origin. You can do all your normaly operations in the temporary repository too.
Make sure the directory contains only the photos you want to create a timelapse from, and that they are in order.
Rename files to a sequence starting from 00001
rename -N 00001 -e 's/.*/$N.JPG/' *.JPG
Convert the sequence of photos like 00001.JPG, 00002.JPG, etc. to a MP4.
ffmpeg -r 24 -pattern_type glob -i '*.JPG' -i %05d.JPG -s hd1080 -vcodec libx264 timelapse.mp4
This creates a 24fps 1080p MP4 video
#!/usr/bin/env node
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let dataStream = '';
process.stdin.on("data", input => (dataStream += input));
process.stdin.on("end", () => processStream(dataStream));
function processStream(data) {
...
}
function createJwt(body: object) {
const encode = (data: any) => Buffer.from(JSON.stringify(data)).toString('base64url');
const header = encode({
"alg": "HS256",
"typ": "JWT"
});
const body = encode(body);
const token = header + '.' + body;
const signature = crypto.createHmac('sha256', Buffer.from("secret")).update(token).digest().toString('base64url');
return token + "." + signature;
}
Allows you to checkout a new branch while you're working on another and don't want to commit/stash your changes.
# create
git worktree add -b <branch-name> <location>
# remove
git worktree list
git worktree remove <directory-name>
git worktree prune
convert -density 130 input.pdf -rotate 0.2 -attenuate 0.2 +noise Multiplicative -colorspace Gray output.pdf