Skip to content

Instantly share code, notes, and snippets.

View Himura2la's full-sized avatar
💭
Nya?

Himura Kazuto Himura2la

💭
Nya?
View GitHub Profile
@Himura2la
Himura2la / gnome3-add-to-directory.sh
Last active November 10, 2020 11:43
Add a .desktop file (that is not prefent in Software app) into a directory
gsettings set org.gnome.desktop.app-folders.folder:/org/gnome/desktop/app-folders/folders/Utilities/ apps "[..., 'com.github.micahflee.torbrowser-launcher.settings.desktop']"
https://developer.gnome.org/AppFolders/
@Himura2la
Himura2la / dos2unix.sh
Created July 8, 2020 07:27
dos2unix with find and sed
find . -type f -regex '.*\.\(yml\|json\)$' -exec sed -i $'s/\r$//' '{}' \; -exec echo "Line endings changed to LF in {}" \;
@Himura2la
Himura2la / MassReplace.ps1
Last active March 5, 2021 13:18
Replace all occurrences of a string in a directory
function MassReplace {
param (
[Parameter(Mandatory=$true)] [string] $Path,
[Parameter(Mandatory=$true)] [string] $Include,
[Parameter(Mandatory=$true)] [string] $FindString,
[Parameter(Mandatory=$true)] [string] $ReplaceString
)
Get-ChildItem $Path -Include $Include -Recurse
| Select-String $FindString -SimpleMatch
| Group-Object -Property Path
@Himura2la
Himura2la / Copy-Filtered.ps1
Created August 3, 2020 09:44
Copy-Item -Recurse with multiple filter
function Copy-Filtered {
param (
[string] $Source,
[string] $Target,
[string[]] $Filter
)
$ResolvedSource = Resolve-Path $Source
$NormalizedSource = $ResolvedSource.Path.TrimEnd([IO.Path]::DirectorySeparatorChar) + [IO.Path]::DirectorySeparatorChar
Get-ChildItem $Source -Include $Filter -Recurse | ForEach-Object {
$RelativeItemSource = $_.FullName.Replace($NormalizedSource, '')
#!/bin/bash
usage_msg="Usage: $0 ssh_address local_image_tag"
ssh_address=${1?$usage_msg}
image_name=${2?$usage_msg}
echo "Sending gzipped image '$image_name' to '$ssh_address' via ssh..."
docker image save $image_name | gzip | ssh $ssh_address 'zcat | docker image load'
echo "Connecting to '$ssh_address' via ssh to seamlessly deploy '$image_name'..."
@Himura2la
Himura2la / Dockerfile
Last active August 25, 2020 17:40
sshd
FROM debian:stable-slim
EXPOSE 22
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd &&\
sed -e 's/#PasswordAuthentication yes/PasswordAuthentication no/' \
-e 's/#PermitRootLogin prohibit-password/PermitRootLogin no/' \
-e 's/#ClientAliveInterval 0/ClientAliveInterval 60/' \
-i /etc/ssh/sshd_config
RUN useradd -m -s /bin/bash user
COPY authorized_keys /home/user/.ssh/authorized_keys
@Himura2la
Himura2la / switch-tab.sh
Created September 8, 2020 10:07
Switch tab in a browser on X11 screen :0
#!/bin/sh
DISPLAY=:0 /usr/bin/xdotool key Ctrl+Tab
@Himura2la
Himura2la / systemd-ulimits.sh
Last active September 24, 2020 06:41
Fix "Cannot allocate memory" warning of jackd in realtime mode in sessions started from systemd
$ cat /etc/security/limits.d/95-jack.conf
# Default limits for users of jack-audio-connection-kit
@jackuser - rtprio 70
@jackuser - memlock 4194304
@pulse-rt - rtprio 20
@pulse-rt - nice -20
# This applies only to console sessions.
@Himura2la
Himura2la / update-grub
Last active May 31, 2021 19:25
update-grub equivalent for RHEL, CentOS, and Fedora
sudo grub2-mkconfig -o "$(sudo readlink -e /etc/grub2.cfg)"
@Himura2la
Himura2la / add-user.sh
Last active June 29, 2023 14:46
Create a linux user for another person
new_user=''
user_public_key=''
sudo useradd -mG sudo -s /bin/bash $new_user
sudo passwd --delete $new_user
sudo mkdir /home/$new_user/.ssh
echo "$user_public_key" | sudo tee /home/$new_user/.ssh/authorized_keys
sudo chmod -v 700 /home/$new_user/.ssh
sudo chmod -v 600 /home/$new_user/.ssh/authorized_keys
sudo chown -vR $new_user:$new_user /home/$new_user/.ssh