mirror of
https://github.com/sahinakkaya/til.git
synced 2024-12-21 22:59:39 +01:00
fix: Add syntax highlighting to code blocks
This commit is contained in:
parent
871f28d44c
commit
089e6ebae8
@ -1,5 +1,5 @@
|
||||
You can use `touch` to change modification date or time of a file:
|
||||
```
|
||||
```bash
|
||||
touch -d 20210703 filename
|
||||
|
||||
# Set the times on a file to a specific date and time:
|
||||
@ -7,8 +7,8 @@ touch -t YYYYMMDDHHMM.SS filename
|
||||
```
|
||||
|
||||
|
||||
or use the times from a file to set the times on a second file:
|
||||
... or use the times from a file to set the times on a second file:
|
||||
|
||||
```
|
||||
```bash
|
||||
touch -r filename filename2
|
||||
```
|
||||
|
@ -1,5 +1,5 @@
|
||||
You can get the size of a file in bytes with:
|
||||
```
|
||||
```bash
|
||||
stat -c %s file_name
|
||||
# example
|
||||
size=$(stat -c %s $myfile)
|
||||
|
@ -1,12 +1,12 @@
|
||||
You can loop through the files with:
|
||||
```
|
||||
```bash
|
||||
for f in * ; do
|
||||
echo $f
|
||||
done
|
||||
```
|
||||
|
||||
If you want to loop through only directories:
|
||||
```
|
||||
```bash
|
||||
for d in */ ; do
|
||||
echo $d
|
||||
done
|
||||
|
@ -1,5 +1,5 @@
|
||||
You can move every file (except the hidden ones) up by one level in the hierarchy with something like this:
|
||||
```
|
||||
```bash
|
||||
for d in */ ; do
|
||||
mv $d* .
|
||||
rmdir $d # optional
|
||||
|
@ -1,8 +1,8 @@
|
||||
1. Redirect stdout to one file and stderr to another file:
|
||||
|
||||
command > out 2>error
|
||||
|
||||
```bash
|
||||
command > out 2>error
|
||||
```
|
||||
2. Redirect stdout to a file `out`, and then redirect stderr to stdout:
|
||||
|
||||
command > out 2>&1
|
||||
|
||||
```bash
|
||||
command > out 2>&1
|
||||
```
|
||||
|
@ -1,6 +1,6 @@
|
||||
You can split a string with `cut`:
|
||||
|
||||
```
|
||||
```bash
|
||||
foo="hello-world-bye-world"
|
||||
bar=$(echo $foo | cut -d"-" -f2)
|
||||
echo $bar
|
||||
|
@ -1,6 +1,6 @@
|
||||
I have lots of images of a scene from sunrise to sunset and my wallpaper is automaticatilly set to one of them based on the hour of the day. But you know what? I LOVE customizing my machine and I WANT MORE! I want the transition to be smooth af. To make this possible I need to generate images. And here is the result of literally 5 minutes of google search:
|
||||
I have lots of images of a scene from sunrise to sunset and my wallpaper is automatically set to one of them based on the hour of the day. But you know what? I LOVE customizing my machine and I WANT MORE! I want the transition to be smooth af. To make this possible I need to generate images. And here is the result of literally 5 minutes of google search:
|
||||
|
||||
```
|
||||
```bash
|
||||
convert A.jpg B.jpg -morph 10 out.jpg
|
||||
```
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
Most of the time, `xev` will be enough to know exactly which key is pressed but it generates a lot of output and sometimes that is overwhelming. If you find yourself in this situation try:
|
||||
```
|
||||
```bash
|
||||
showkey -a
|
||||
```
|
||||
|
@ -1,7 +1,8 @@
|
||||
You can join multiple images into one using `convert`:
|
||||
|
||||
# join vertically
|
||||
convert in1.png in2.png -append out.png
|
||||
```bash
|
||||
# join vertically
|
||||
convert in1.png in2.png -append out.png
|
||||
|
||||
# join horizontally
|
||||
convert in1.png in2.png +append out.png
|
||||
# join horizontally
|
||||
convert in1.png in2.png +append out.png
|
||||
```
|
||||
|
@ -1,22 +1,26 @@
|
||||
You can join multiple images to pdf using `convert`:
|
||||
|
||||
convert *.png out.pdf
|
||||
```bash
|
||||
convert *.png out.pdf
|
||||
```
|
||||
|
||||
If you get an error like
|
||||
|
||||
convert-im6.q16: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408.
|
||||
```
|
||||
convert-im6.q16: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408.
|
||||
```
|
||||
|
||||
follow the steps below:
|
||||
|
||||
sudo vim /etc/ImageMagick-6/policy.xml
|
||||
```bash
|
||||
sudo vim /etc/ImageMagick-6/policy.xml
|
||||
```
|
||||
|
||||
and replace the line
|
||||
|
||||
<policy domain="coder" rights="none" pattern="PDF" />
|
||||
|
||||
```xml
|
||||
<policy domain="coder" rights="none" pattern="PDF" />
|
||||
```
|
||||
with
|
||||
|
||||
<policy domain="coder" rights="read|write" pattern="PDF" />
|
||||
|
||||
```xml
|
||||
<policy domain="coder" rights="read|write" pattern="PDF" />
|
||||
```
|
||||
|
||||
[source](https://askubuntu.com/questions/1081895/trouble-with-batch-conversion-of-png-to-pdf-using-convert)
|
||||
|
@ -1,6 +1,6 @@
|
||||
You can join multiple pdf files into one using this command:
|
||||
|
||||
```
|
||||
```bash
|
||||
pdfunite in-1.pdf in-2.pdf in-n.pdf out.pdf
|
||||
```
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
You can extract certain parts of a pdf file with this:
|
||||
|
||||
```
|
||||
```bash
|
||||
pdfjam original.pdf 5-10 -o out.pdf
|
||||
```
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
You can use below command to create a virtual environment which contains installed packages:
|
||||
```
|
||||
```bash
|
||||
virtualenv venv --system-site-packages
|
||||
```
|
||||
|
@ -1,3 +1,3 @@
|
||||
```
|
||||
```bash
|
||||
readlink -f /path/to/file
|
||||
```
|
||||
|
@ -1,4 +1,4 @@
|
||||
```
|
||||
```bash
|
||||
psql dbname username
|
||||
|
||||
# example
|
||||
|
@ -1,9 +1,9 @@
|
||||
If you have an existing repository and want to add a new remote you can use this command:
|
||||
```
|
||||
```bash
|
||||
git remote add <name> <url>
|
||||
```
|
||||
Example:
|
||||
```
|
||||
```bash
|
||||
git remote add origin git@github.com:Asocia/til.git
|
||||
git push -u origin my_branch
|
||||
```
|
||||
|
@ -1,7 +1,7 @@
|
||||
You can change author of your commits to anyone. Let's make all the commit's of the current repository Torvalds :D Luckily we know his email address so this will be very easy. Just run:
|
||||
```
|
||||
You can change author of your commits to anyone. Let's make all the commits of the current repository Torvalds's :D Luckily we know his email address so this will be very easy. Just run:
|
||||
```bash
|
||||
git filter-branch --env-filter '
|
||||
OLD_EMAIL="akkayas17@itu.edu.tr"
|
||||
OLD_EMAIL="old_email@domain.com"
|
||||
CORRECT_NAME="Linus Torvals"
|
||||
CORRECT_EMAIL="torvalds@linux-foundation.org"
|
||||
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
|
||||
|
@ -1,6 +1,6 @@
|
||||
You have a commit which contains a good code change but it is in another branch?
|
||||
|
||||
```
|
||||
```bash
|
||||
# pick the commit
|
||||
git cherry-pick <sha>
|
||||
|
||||
|
@ -4,18 +4,18 @@ I'm reading Pro Git book and I learn some cool stuff. I don't know if I'm going
|
||||
|
||||
If you to know which changes are made since some time, use `--since` option like:
|
||||
|
||||
```
|
||||
```bash
|
||||
git log --since=2.weeks
|
||||
```
|
||||
or until some time
|
||||
```
|
||||
```bash
|
||||
git log --until="20-01-2020"
|
||||
```
|
||||
|
||||
These commands works with lots of formats, you can specify a specific date like "2008-01-15", or a relative date such as "2 years 1 day 3 minutes ago"
|
||||
|
||||
The --author option allows you to filter on a specific author
|
||||
```
|
||||
```bash
|
||||
git log --author="Asocia"
|
||||
```
|
||||
|
||||
@ -23,7 +23,7 @@ git log --author="Asocia"
|
||||
|
||||
|
||||
Another really helpful filter is the -S option (colloquially referred to as Git’s “pickaxe” option), which takes a string and shows only those commits that changed the number of occurrences of that string. For instance, if you wanted to find the last commit that added or removed a reference to a specific function, you could call:
|
||||
```
|
||||
```bash
|
||||
git log -S function_name
|
||||
```
|
||||
|
||||
@ -33,11 +33,11 @@ git log -S function_name
|
||||
|
||||
We’ve mentioned and given some demonstrations of how the git clone command implicitly adds the origin remote for you. Here’s how to add a new remote explicitly. To add a new remote Git repository as a shortname you can reference easily, run git remote add <shortname> <url>:
|
||||
|
||||
```
|
||||
$ git remote -v
|
||||
$ git remote add pb https://github.com/paulboone/ticgit
|
||||
$ git remote -v
|
||||
$ git fetch pb
|
||||
```bash
|
||||
git remote -v
|
||||
git remote add pb https://github.com/paulboone/ticgit
|
||||
git remote -v
|
||||
git fetch pb
|
||||
```
|
||||
Paul’s master branch is now accessible locally as pb/master — you can merge it into one of your branches, or you can check out a local branch at that point if you want to inspect it.
|
||||
|
||||
@ -52,23 +52,23 @@ From Git version 2.23 onwards you can use `git switch` instead of `git checkout`
|
||||
- Renaming branches
|
||||
|
||||
Suppose you have a branch that is called `bad-branch-name` and you want to change it to `corrected-branch-name`, while keeping all history. You also want to change the branch name on the remote (GitHub, GitLab, other server). How do you do this? Rename the branch locally with the `git branch --move` command:
|
||||
```
|
||||
```bash
|
||||
git branch --move bad-branch-name corrected-branch-name
|
||||
```
|
||||
|
||||
This replaces your `bad-branch-name` with `corrected-branch-name`, but this change is only local for now. To let others see the corrected branch on the remote, push it:
|
||||
|
||||
```
|
||||
```bash
|
||||
git push --set-upstream origin corrected-branch-name
|
||||
```
|
||||
To delete the old branch name:
|
||||
```
|
||||
```bash
|
||||
git push origin --delete bad-branch-name
|
||||
```
|
||||
|
||||
- Pushing a local branch into a remote branch that is named differently
|
||||
|
||||
```
|
||||
```bash
|
||||
# our branch is serverfix and we don't want to push it with this name
|
||||
git push origin serverfix:awesomebranch
|
||||
```
|
||||
|
@ -1,6 +1,6 @@
|
||||
Let's say you are in `wip` branch and you didn't push your changes to server yet. If you want to get all the changes from master:
|
||||
|
||||
```
|
||||
```bash
|
||||
git checkout master
|
||||
git pull
|
||||
git checkout wip
|
||||
|
@ -1,10 +1,10 @@
|
||||
When you do
|
||||
|
||||
```
|
||||
```bash
|
||||
git rebase -i commitish
|
||||
```
|
||||
and edit some commits, you will recreate the history hence all the commits coming after edited one will have the same date and time. If you don't want this behaviour here is the trick:
|
||||
```
|
||||
```bash
|
||||
git rebase --committer-date-is-author-date -i commitish
|
||||
```
|
||||
Note that you need git version 23.19 or greater to do this in interactive mode.
|
||||
|
@ -1,7 +1,7 @@
|
||||
From Pro Git book:
|
||||
|
||||
> Another useful thing you may want to do is to keep the file in your working tree but remove it from your staging area. In other words, you may want to keep the file on your hard drive but not have Git track it anymore. This is particularly useful if you forgot to add something to your .gitignore file and accidentally staged it, like a large log file or a bunch of .a compiled files. To do this, use the --cached option:
|
||||
```
|
||||
```bash
|
||||
git rm --cached README
|
||||
```
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
You can remove untracked files with `git-clean`.
|
||||
|
||||
```
|
||||
```bash
|
||||
# Show which files will be removed
|
||||
git clean -nd
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
You can clone a repository with ssh and pull/push without having to enter your credentials. If you already cloned it with https and want to change your remote url, do this:
|
||||
```
|
||||
```bash
|
||||
❯ git remote -v
|
||||
origin https://github.com/Asocia/dotfiles.git (fetch)
|
||||
origin https://github.com/Asocia/dotfiles.git (push)
|
||||
|
@ -1,5 +1,5 @@
|
||||
To see the changes in both staging area and working tree, use:
|
||||
|
||||
```
|
||||
```bash
|
||||
git diff HEAD
|
||||
```
|
||||
|
@ -1,16 +1,16 @@
|
||||
You can add filename to `git log` to view all the commit history of a file:
|
||||
|
||||
```
|
||||
```bash
|
||||
git log my_file
|
||||
```
|
||||
|
||||
If you want to view diff's, add `-p` option:
|
||||
```
|
||||
```bash
|
||||
git log -p my_file
|
||||
```
|
||||
|
||||
If you want to continue listing the file history beyond renames, add `--follow` option:
|
||||
```
|
||||
```bash
|
||||
git log --follow -p my_file
|
||||
```
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
You can generate authentication keys and use it with ssh to login. First run the below command if you don't have any (it won't overwrite if you already have one):
|
||||
|
||||
```
|
||||
```bash
|
||||
ssh-keygen
|
||||
```
|
||||
|
||||
Then copy your public key to remote server with this:
|
||||
```
|
||||
```bash
|
||||
ssh-copy-id name@host
|
||||
```
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
YOU CAN TOGGLE CAPS LOCK FROM COMMAND LINE BY DOING:
|
||||
```
|
||||
```bash
|
||||
xdotool key Caps_Lock
|
||||
```
|
||||
|
||||
|
@ -5,13 +5,13 @@ Read [this](https://wiki.archlinux.org/title/backlight) and you are done :D
|
||||
Here is the tl;dr part.
|
||||
|
||||
Run `ls /sys/class/backlight/` to see which graphics card is managing your backlight. I'm assuming you get an ouput like `intel_backlight`. Then run this:
|
||||
```
|
||||
```bash
|
||||
ls /sys/class/backlight/intel_backlight
|
||||
actual_brightness bl_power brightness device/
|
||||
max_brightness power/ scale subsystem/ type uevent
|
||||
```
|
||||
Read the `max_brightness` value and then set your brightness to something smaller than that value:
|
||||
```
|
||||
```bash
|
||||
cat /sys/class/backlight/intel_backlight/max_brightness
|
||||
echo 100 > /sys/class/backlight/intel_backlight/brightness
|
||||
```
|
||||
@ -23,7 +23,7 @@ RUN+="/bin/chgrp video /sys/class/backlight/intel_backlight/brightness"
|
||||
RUN+="/bin/chmod g+w /sys/class/backlight/intel_backlight/brightness"
|
||||
```
|
||||
and add yourself to the `video` group.
|
||||
```
|
||||
```bash
|
||||
sudo usermod -aG video $USER
|
||||
```
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
If you want to connect to a device via bluetooth:
|
||||
```
|
||||
```bash
|
||||
sudo systemctl enable bluetooth.service
|
||||
bluetoothctl power on
|
||||
bluetoothctl devices # to find the mac address of your device
|
||||
|
@ -7,7 +7,7 @@ N: See apt-secure(8) manpage for repository creation and user configuration deta
|
||||
|
||||
You will need to find corresponding file in `sources.list.d` and delete it.
|
||||
|
||||
```
|
||||
```bash
|
||||
cd /etc/apt/sources.list.d
|
||||
sudo rm bad-repo.list
|
||||
```
|
||||
|
@ -18,11 +18,11 @@ While this is effective it certainly isn’t copy-paste drop dead simple and is
|
||||
|
||||
## Doing it the X11 config way
|
||||
X11 provides configurations in a directory “X11/xorg.conf.d/” this directory could live in various places on your system depending on your distribution. However, X11 will always attempt to also load configurations from /etc/X11/xorg.conf.d/ when present. To ensure the directory exists, run:
|
||||
```
|
||||
```bash
|
||||
sudo mkdir -p /etc/X11/xorg.conf.d
|
||||
```
|
||||
Next we’ll create a new file “90-touchpad.conf”. The configuration file names end with .conf and are read in ASCII order—by convention file names begin with two digits followed by a dash.
|
||||
```
|
||||
```bash
|
||||
sudo touch /etc/X11/xorg.conf.d/90-touchpad.conf
|
||||
```
|
||||
Now open up the file your editor of choice (with suitable write permission of course) and paste the following:
|
||||
|
@ -4,7 +4,7 @@ Here is how it should be done:
|
||||
|
||||
If you want to remap it for X server, add the following line to your `~/.xsession` or `~/.xinitrc`. Make sure to add it before `exec whatever_window_manager` you are using:
|
||||
|
||||
```
|
||||
```bash
|
||||
setxkbmap -option 'caps:ctrl_modifier'
|
||||
```
|
||||
[source](https://superuser.com/questions/566871/how-to-map-the-caps-lock-key-to-escape-key-in-arch-linux)
|
||||
|
@ -1,6 +1,6 @@
|
||||
Recently, I switched to dvorak layout and I am using it everywhere to get used to it. This was the command that worked everywhere (including the login screen):
|
||||
|
||||
```
|
||||
```bash
|
||||
localectl --no-convert set-x11-keymap us pc105 dvp caps:ctrl_modifier
|
||||
```
|
||||
|
||||
|
@ -3,7 +3,7 @@ When my Ctrl key broken, I remapped Capslock to Ctrl as it was the most useless
|
||||
I am a vim user and I don't use Capslock other than typing some constant variable names or SQL syntax etc. They are all happening in vim, specifically, in insert mode. Whenever I switch to normal mode, I want my Capslock to be off. I sometimes forget and instead of moving down with `j`, I find myself `J`oining lines. This happened more than 3 times so it is time to do something.
|
||||
|
||||
I could solve this problem in keyboard level because I have a programmable keyboard. I didn't want to this because sometimes I use my laptop's keyboard and I don't want them to behave differently. So I solved it on OS level. Here are the commands that I run in order to achieve this effect:
|
||||
```
|
||||
```bash
|
||||
mkdir -p ~/.xkb/keymap/
|
||||
mkdir -p ~/.xkb/symbols/
|
||||
vim ~/.xkb/symbols/mysymbols
|
||||
|
@ -1,5 +1,5 @@
|
||||
Make sure that you are not inside the mounted path.
|
||||
|
||||
``````
|
||||
```bash
|
||||
sudo umount /path/to/dev
|
||||
``````
|
||||
```
|
||||
|
@ -1,5 +1,5 @@
|
||||
Today I wanted to ssh into my desktop from my laptop. They were both connected to my phone. Laptop was connected via Wi-Fi and the desktop was connected via USB tethering. Since they are not connected in the same way, they were on different networks and it was not possible to ssh into the other computer. I searched about the problem and found [this article](https://www.systutorials.com/port-forwarding-using-iptables/). Since my phone was rooted, I could run any command I want. The final set of commands which allowed me to ssh between each computers were:
|
||||
```
|
||||
```bash
|
||||
# from laptop to desktop
|
||||
iptables -t nat -A POSTROUTING ! -d 192.168.43.0/24 -o rndis0 -j MASQUERADE
|
||||
iptables -A PREROUTING -t nat -i swlan0 -p tcp --dport 22 -j DNAT --to 192.168.42.17:22
|
||||
|
@ -1,6 +1,6 @@
|
||||
You can execute vim commands in terminal by prefixing your commands with `+` symbol:
|
||||
|
||||
```
|
||||
```bash
|
||||
vim filename +/searchterm
|
||||
vim +PlugInstall
|
||||
vim filename +g/foo/d
|
||||
|
@ -1,5 +1,5 @@
|
||||
Typically files ending with a ~ are backups created by editors like emacs, nano or vi. Set `backupdir` to some other location if you don't want to see them everywhere.
|
||||
|
||||
```
|
||||
```vim
|
||||
set backupdir=/path/to/somewhere
|
||||
```
|
||||
|
@ -1,6 +1,6 @@
|
||||
You can search through multiple files using `vimgrep` command.
|
||||
|
||||
```
|
||||
```vim
|
||||
# search for string all python files in the current dir
|
||||
:vimgrep string *.py
|
||||
# search for string all python files in the current dir and subdir of the current dir
|
||||
|
@ -1,6 +1,6 @@
|
||||
The global command `:g[lobal]` is very powerful. It is used to execute a command matching a pattern. The syntax is
|
||||
|
||||
```
|
||||
```vim
|
||||
:[range]g/pattern/cmd
|
||||
```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user