terminal

audio stereo to mono script

Convert all files as duo mono files

create a folder in which you want to convert the stereo clips to mono.

#!/bin/bash

for f in .wav; do ffmpeg -i "$f" \
-filter_complex "[0:a]channelsplit=channel_layout=stereo[L][R]" \
-map "[L]" "${f%.
}_EXTRACTED_Lt.wav" \
-map "[R]" "${f%.*}_EXTRACTED_Rt.wav"; done

copy paste json pretty print

in terminal
pbpaste | json_pp | pbcopy

speedtest cli

curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python -

youtube dl

install youtube-dl

sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

youtube-dl is replaced by yt-dlp

yt-dlp -x --audio-format mp3 --audio-quality 0 "$1" | awk '{gsub(/\[[^]]*\]/,""); print}'
alias yt='function _yt() { yt-dlp -x --audio-format mp3 --audio-quality 0 "$1" | awk "{gsub(/\\[[^\\]]*\\]/,\"\"); print}"; }; _yt'

mp3

youtube-dl --extract-audio --audio-format mp3 URL-vid

playlist

youtube-dl --extract-audio --audio-format mp3 -o "%(title)s.%(ext)s" URL-playlist
youtube-dl -cit --extract-audio --audio-format mp3 URL-playlist
Tags: 

Add new remote on github from cli

curl -u 'USER' https://api.github.com/user/repos -d '{"name":"PROJNAME"}'

Windows cli check for running at port 1234

netstat -ano | findstr :<PORT>
tskill typeyourPIDhere 
or taskkill /PID 14328 /F

Spotlight

problems with indexing , not indexing, stopped indexing.

1)

  • Enable Indexing – sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
  • Disable Indexing – sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

2)
Open Terminal
Type - not copy! - the following but wait a few second between them:

sudo mdutil -i off /
sudo mdutil -i on /
sudo mdutil -E /

If, after a few minutes, Spotlight is still not indexing, try running this command, followed by the three commands above:
sudo rm -rf /.Spotlight-V100

Swift App from Terminal

ObjC article by chris eidhof

// Run any SwiftUI view as a Mac app.

import Cocoa
import SwiftUI

NSApplication.shared.run {
    VStack {
        Text("Hello, World")
            .padding()
            .background(Capsule().fill(Color.blue))
            .padding()
    }
    .frame(maxWidth: .infinity, maxHeight: .infinity)

}

extension NSApplication {
    public func run<V: View>(@ViewBuilder view: () -> V) {
        let appDelegate = AppDelegate(view())
        NSApp.setActivationPolicy(.regular)
        mainMenu = customMenu
        delegate = appDelegate
        run()
    }
}

// Inspired by https://www.cocoawithlove.com/2010/09/minimalist-cocoa-programming.html

extension NSApplication {
    var customMenu: NSMenu {
        let appMenu = NSMenuItem()
        appMenu.submenu = NSMenu()
        let appName = ProcessInfo.processInfo.processName
        appMenu.submenu?.addItem(NSMenuItem(title: "About \(appName)", action: #selector(NSApplication.orderFrontStandardAboutPanel(_:)), keyEquivalent: ""))
        appMenu.submenu?.addItem(NSMenuItem.separator())
        let services = NSMenuItem(title: "Services", action: nil, keyEquivalent: "")
        self.servicesMenu = NSMenu()
        services.submenu = self.servicesMenu
        appMenu.submenu?.addItem(services)
        appMenu.submenu?.addItem(NSMenuItem.separator())
        appMenu.submenu?.addItem(NSMenuItem(title: "Hide \(appName)", action: #selector(NSApplication.hide(_:)), keyEquivalent: "h"))
        let hideOthers = NSMenuItem(title: "Hide Others", action: #selector(NSApplication.hideOtherApplications(_:)), keyEquivalent: "h")
        hideOthers.keyEquivalentModifierMask = [.command, .option]
        appMenu.submenu?.addItem(hideOthers)
        appMenu.submenu?.addItem(NSMenuItem(title: "Show All", action: #selector(NSApplication.unhideAllApplications(_:)), keyEquivalent: ""))
        appMenu.submenu?.addItem(NSMenuItem.separator())
        appMenu.submenu?.addItem(NSMenuItem(title: "Quit \(appName)", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q"))

        let windowMenu = NSMenuItem()
        windowMenu.submenu = NSMenu(title: "Window")
        windowMenu.submenu?.addItem(NSMenuItem(title: "Minmize", action: #selector(NSWindow.miniaturize(_:)), keyEquivalent: "m"))
        windowMenu.submenu?.addItem(NSMenuItem(title: "Zoom", action: #selector(NSWindow.performZoom(_:)), keyEquivalent: ""))
        windowMenu.submenu?.addItem(NSMenuItem.separator())
        windowMenu.submenu?.addItem(NSMenuItem(title: "Show All", action: #selector(NSApplication.arrangeInFront(_:)), keyEquivalent: "m"))

        let mainMenu = NSMenu(title: "Main Menu")
        mainMenu.addItem(appMenu)
        mainMenu.addItem(windowMenu)
        return mainMenu
    }
}

class AppDelegate<V: View>: NSObject, NSApplicationDelegate, NSWindowDelegate {
    init(_ contentView: V) {
        self.contentView = contentView

    }
    var window: NSWindow!
    var hostingView: NSView?
    var contentView: V

    func applicationDidFinishLaunching(_ notification: Notification) {
        window = NSWindow(
            contentRect: NSRect(x: 0, y: 0, width: 480, height: 300),
            styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
            backing: .buffered, defer: false)
        window.center()
        window.setFrameAutosaveName("Main Window")
        hostingView = NSHostingView(rootView: contentView)
        window.contentView = hostingView
        window.makeKeyAndOrderFront(nil)
        window.delegate = self
        NSApp.activate(ignoringOtherApps: true)
    }
}

heic convert

# convert any HEIC image in a directory to jpg format
magick mogrify -monitor -format jpg *.HEIC

# convert an HEIC image to a jpg image
magick convert example_image.HEIC example_image.jpg

Login ssh automation

import sys
import pyperclip
import subprocess

if len(sys.argv) == 1:
    print('login func needs client to login...')
elif sys.argv[1] == 'do':
    print('login at do, use paste')
    cb = pyperclip.copy('Password')
    bashCommand = "echo apt update"
    subprocess.call(["ssh", "user@ip.address.0.0"])
else:
    print('No login available for '+ sys.argv[1])

sys.exit(1)

adjust zshrc in

~/.zshrc add location python3 and filelocation

alias li="/Users/hjhubeek/Documents/development/python/li/bin/python /Users/hjhubeek/Documents/development/python/li/li.py"

Git foreach use cases

What did I do before the holidays?

git for-each-ref --count=30 --sort=-committerdate refs/heads/ --format='%(refname:short)'

sort by date

git for-each-ref --sort=-committerdate refs/heads/

list finale files in dir to txt file

ls -1 | sed -e 's/ C.musx$//' > songs.txt

Tags: 

curl statuscode

to get via curl a statuscode

curl -I www.website.com

xcrun simctl

xcrun simctl list
xcrun simctl boot UUID
xcrun simctl list | grep Booted
xcrun simctl delete unavailable

remove mongo

# See if mongo is in the launch/startup list
launchctl list | grep mongo

# Remove mongodb from the launch/startup
launchctl remove homebrew.mxcl.mongodb

# Kill the mongod process just in case it's running
pkill -f mongod

# Now you can safely remove mongodb using Homebrew
brew uninstall mongodb

Tags: 

Docker

cleanup

~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2
never shrinks...

Dockerfile recipes

Java hello

FROM openjdk:14-alpine
COPY out/artifacts/testdockerhello_jar/testdockerhello.jar /usr/src/hello.jar
CMD java -cp /usr/src/hello.jar Main

Spring basic

with maven pom.

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <finalName>docker-spring-demo</finalName>
    </build>

Dockerfile
FROM openjdk:11

EXPOSE 8080

ADD target/docker-spring-demo.jar app.jar

ENTRYPOINT ["java","-jar", "app.jar"]

Mysql recipe

docker run --name mysql -e MYSQL_USER=user -e MYSQL_PASSWORD=password -e MYSQL_DATABASE=databasename -p 3306:3306 -d mysql/mysql-server

Sails

run sails from local dir in docker conatiner
docker container run -it -p 1337:1337 -v $(pwd):/server artificial/docker-sails /bin/bash

Swift

run docker app
then

docker pull swift
docker pull postgres:alpine

docker container run -d -p 3306:3306 --name mysql -e MYSQL_RANDOM_ROOT_PASSWORD=yes  mysql
docker container run --name mysql -p 3306:3306 -e MYSQL_RANDOM_ROOT_PASSWORD=yes -d mysql
docker container logs mysql
docker exec -it mysql bash -l

docker container run -d --name mysql -e MYSQL_ROOT_PASSWORD=root -p 3306 -v /Users/lappie2010/Documents/docker/mysql/:/var/lib/mysql mysql


docker container logs mysql

docker container run -d --name webserver -p 8080:80 httpd

docker container run -d --name proxy -p 80:80 nginx


docker run --cap-add sys_ptrace -it --privileged=true swift bash

Docker Mysql + Wordpress

docker container run -d \
    --name wordpress \
--link mysql:mysql\
    -p 8080:80 \
    -e WORDPRESS_DB_PASSWORD=root \
    wordpress

    docker container run -d \
        --name mysql \
        -e MYSQL_ROOT_PASSWORD=root \
        -e MYSQL_DATABASE=wordpress \
        mysql

Fish, bash commands as functions

edit start .bashrc

~/.config/fish/config.fish

functions

p/crossword> function nrh
                               npm run hot
                       end
p/crossword> funcsave nrh
p/crossword> nrh
make Atom.app run from terminal:
ln -s /Applications/Atom.app/Contents/Resources/app/atom.sh /usr/local/bin/atom
make function in Fish:
nano ~/.config/fish/functions/atom.fish
some functions:
function atom
    bash -c 'atom .'
end
function pstorm
    bash -c 'open -a /Applications/PhpStorm.app .'
end

function xcodeclean
        command rm -rf ~/Library/Developer/Xcode/DerivedData/*
end

function ll
    ls -lahG $argv
end

function rmpoddata
    pod deintegrate
    rm -rf Pods
    rm -rf Podfile.lock
    pod install
end

function rmderiveddata
    sudo rm -rf ~/Library/Developer/Xcode/DerivedData/*
end

Tags: 

delete with extension

find /path . -name '*.orig' -type f -delete

Tags: 

Icon create

after: brew install imagemagick
create iconcreate.sh

#!/bin/bash
for size in {76,40,29,60,57,50,72,167}; do for scale in {1,2,3}; do
    if [[ $scale == 1 ]]; then
        filename="icon_${size}.png"
    else
        filename="icon_${size}@${scale}x.png"
    fi
    gm convert "icon.png" -resize "$(( $scale * $size ))x$(( $scale * $size ))" $
done; done

or
sh iconcreate.sh icon.png

convert $1 -resize 16x16      Icon-16.png
convert $1 -resize 32x32      Icon-16@2x.png
convert $1 -resize 29x29      Icon-Small-29.png          # Settings on iPad and iPhone, and Spotlight on iPhone
convert $1 -resize 58x58      Icon-Small-29@2x.png
convert $1 -resize 87x87      Icon-Small-29@3x.png
convert $1 -resize 32x32      Icon-32.png
convert $1 -resize 64x64      Icon-32@2x.png
convert $1 -resize 40x40      Icon-Small-40.png       # Spotlight
convert $1 -resize 80x80      Icon-Small-40@2x.png       # Spotlight
convert $1 -resize 120x120    Icon-Small-40@3x.png       # Spotlight
convert $1 -resize 50x50      Icon-Small-50.png       # Spotlight on iPad 1/2
convert $1 -resize 57x57      Icon-57.png                # Home screen on non-Retina iPhone/iPod
convert $1 -resize 114x114    Icon-57@2x.png             # Home screen for Retina display iPhone/iPod
convert $1 -resize 120x120    Icon-60@2x.png          # Home screen on iPhone/iPod Touch with retina display
convert $1 -resize 180x180    Icon-60@3x.png          # Home screen on iPhone 6 Plus
convert $1 -resize 72x72      Icon-72.png             # App Store and Home screen on iPad
convert $1 -resize 144x144    Icon-72@2x.png          # Home screen for "The New iPad"
convert $1 -resize 76x76      Icon-76.png             # Home screen on iPad
convert $1 -resize 152x152    Icon-76@2x.png          # Home screen on iPad with retina display
convert $1 -resize 228x228    Icon-76@3x.png
convert $1 -resize 83.5x83.5  Icon-83,5.png
convert $1 -resize 167x167    Icon-83,5@2x.png
convert $1 -resize 128x128    Icon-128.png
convert $1 -resize 256x256    Icon-128@2x.png
convert $1 -resize 256x256    Icon-256.png
convert $1 -resize 512x512    Icon-256@2x.png
convert $1 -resize 512x512    Icon-512.png
convert $1 -resize 1024x1024  iTunesArtwork@2x.png   # App list in iTunes for devices with retina display
convert $1 -resize 1024x1024  Icon-512@2x.png
convert $1 -resize 512x512    iTunesArtwork.png       # Ad Hoc iTunes

rename extension

for file in *.html
do
mv "$file" "${file%.html}.txt"
done

Tags: 

print to file

history > history_for_print.txt

Tags: 

kali

service tor status
service tor start
service tor restart

proxychains firefox www.duckduckgo.com
dns leak test
www.dnsleaktest.com

vpn

cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.1.1

nano /etc/dhcp/dhclient.conf
service network-manager restart

firfox
about:config

macchanger -s wlan0 //show

nslookup

nmap scanme.nmap.org -vv //verbose
nmap -oG - 192.168.1.1-255 -p 3000 -vv > /home/scan.txt

curl ipinfo.io/74.207.244.221
location info

edit sites from local machine to dev server

sudo nano /etc/hosts

#server windows linux test
192.168.0.12 test.com
192.168.0.12 example.com

Tags: 

hidden files in terminal mac

defaults write com.apple.finder AppleShowAllFiles YES

killall Finder

Tags: 

find file type in terminal

find . -type f -name "*.txt"

Tags: 
Subscribe to RSS - terminal