Useful links

Table of Contents

I refile computer tips here (and other links) from my bookmarks.

CUE Splitting - ArchWiki   linux emms emacs

Install dependencies:

sudo aptitude install cuetools shntool
#!/bin/sh

# frontend for:            cuetools, shntool, mp3splt
# optional dependencies:    flac, mac, wavpack, ttaenc
# v1.3 sen


SDIR=`pwd`

if [ "$1" = "" ]
  then
    DIR=$SDIR
else
    case $1 in
        -h | --help )
            echo "Usage: cuesplit [Path]"
            echo "       The default path is the current directory."
            exit
            ;;
        * )
        DIR=$1
    esac
fi

echo -e "\

Directory: $DIR
________________________________________
"
cd "$DIR"
TYPE=`ls -t1`

case $TYPE in
    *.ape*)
        mkdir split
        shnsplit -d split -f *.cue -o "flac flac -V --best -o %f -" *.ape -t "%n %p - %t"
        rm -f split/00*pregap*
        cuetag *.cue split/*.flac
        exit
        ;;

    *.flac*)
        mkdir split
        shnsplit -d split -f *.cue -o "flac flac -V --best -o %f -" *.flac -t "%n %p - %t"
        rm -f split/00*pregap*
        cuetag *.cue split/*.flac
        exit
        ;;

    *.mp3*)
        mp3splt -no "@n @p - @t (split)" -c *.cue *.mp3
        cuetag *.cue *split\).mp3
        exit
        ;;

    *.ogg*)
        mp3splt -no "@n @p - @t (split)" -c *.cue *.ogg
        cuetag *.cue *split\).ogg
        exit
        ;;

    *.tta*)
        mkdir split
        shnsplit -d split -f *.cue -o "flac flac -V --best -o %f -" *.tta -t "%n %p - %t"
        rm -f split/00*pregap*
        cuetag *.cue split/*.flac
        exit
        ;;

    *.wv*)
        mkdir split
        shnsplit -d split -f *.cue -o "flac flac -V --best -o %f -" *.wv -t "%n %p - %t"
        rm -f split/00*pregap*
        cuetag *.cue split/*.flac
        exit
        ;;

    *.wav*)
        mkdir split
        shnsplit -d split -f *.cue -o "flac flac -V --best -o %f -" *.wav -t "%n %p - %t"
        rm -f split/00*pregap*
        cuetag *.cue split/*.flac
        exit
        ;;

    * )
    echo "Error: Found no files to split!"
    echo "       --> APE, FLAC, MP3, OGG, TTA, WV, WAV"
esac
exit

captured on: [2018-01-26 Fri 15:47]

Organizing Notes With Refile   emacs

To refile to a top-level heading use this trick

(setq org-refile-use-outline-path 'file)

captured on: [2018-07-24 Tue 20:29]

Mount qcow2 image   linux kvm qemu

This is a quick guide to mounting a qcow2 disk images on your host server. This is useful to reset passwords, edit files, or recover something without the virtual machine running.

#Step 1 - Enable NBD on the Host

modprobe nbd max_part=8

#Step 2 - Connect the QCOW2 as network block device

qemu-nbd --connect=/dev/nbd0 /var/lib/vz/images/100/vm-100-disk-1.qcow2

#Step 3 - Find The Virtual Machine Partitions

fdisk /dev/nbd0 -l

#Step 4 - Mount the partition from the VM

mount /dev/nbd0p1 /mnt/somepoint/

#Step 5 - After you done, unmount and disconnect

umount /mnt/somepoint/
qemu-nbd --disconnect /dev/nbd0
rmmod nbd

#In my case partition didn't receive its own, Fixed by running

partx -a /dev/nbd0

captured on: [2018-06-20 Wed 18:29]

Download lain 8bit tone   lain

youtube-dl https://www.youtube.com/watch?v=N6Jn98ktFw0
ffmpeg -i Serial\ Experiments\ Lain\ \ Opening\ -\ Duvet\ \(8bit\)-N6Jn98ktFw0.mkv -ss 19 -vn -strict -2 -codec:a vorbis lain.ogg

captured on: [2017-12-25 Mon 15:28]

Evaluating Emacs commands in Common lisp   emacs lisp

So I can eval emacs commands and functions from common lisp using the swank function eval-in-emacs

(message (swank:eval-in-emacs '(emacs-version)))

This can be very helpful. Like getting the current emms track.

file:///home/mo/.stumpwmrc#org989a08c captured on: [2018-01-05 Fri 19:11]

Linux disable ip class 6   linux net

sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1

{untitled page} captured on: [2018-01-07 Sun 21:15]

docker remove stopped containers   linux docker

docker rm $(docker ps -a -q) 

Dependecies captured on: [2018-01-18 Thu 12:59]

change the background color   linux x

xsetroot -solid "#222222"

file:///home/mo/.xinitrc# xsetroot -solid "#222222" captured on: [2018-01-19 Fri 16:38]

Apache docker fix sigwinch issue   apache docker

Just remove the -it option (interactive and pseudo tty). and this will work. Run the container captured on: [2018-01-21 Sun 14:37]

docker remove none images (with no name)   docker linux

docker rmi -f $(docker images -a|grep "<none>"|awk '$1=="<none>" {print $3}')

Log - ratox - FIFO based tox client captured on: [2018-01-21 Sun 17:16]

Archive mailing lists from lists.gnu.org   linux emacs gnu wget

wget -N -nH -m ftp://lists.gnu.org/emms-help/

captured on: [2018-01-24 Wed 14:41]

mb2md on mailings lists from lists.gnu.org   emacs eshell

Welcome to the Emacs shell

~/Documents/org $ for file in emacs-devel/* {mb2md -s ~/archives/$file -d ~/Maildir/emacs-devel}

captured on: [2018-01-24 Wed 15:34]

Play pinknoise & brownnoise   sleep linux

This needs sox installed.

play -n synth brownnoise synth pinknoise mix synth sine amod 0.3 20

captured on: [2018-01-26 Fri 15:33]

Emacs org mode make tangled file executable with 755 file permissions   org emacs

:tangle-mode (identity #o755)

Init script captured on: [2018-01-26 Fri 15:56]

Protect against arp poisoning attacks   linux networking

This protects against netcut and other tools like this

sudo arpon -i wlp3s0 -D

captured on: [2018-01-27 Sat 20:10]

Print certain pages from pdf using lp and pdftk   linux

pdftk 1501129577488.pdf cat 278-282 output /dev/stdout |lp -d "Canon_MP140_series"

captured on: [2018-02-01 Thu 10:04]

org mode change image width   org emacs

Have to reload inline images display for this to take place.

(setq org-image-actual-width 1100)

General idea behind symmetric algorithms captured on: [2018-02-07 Wed 07:09]

python split string every nth character   python

[line[i:i+n] for i in range(0, len(line), n)]

captured on: [2018-02-11 Sun 18:05]

Stream audio using ncat and ffmpeg   linux stream ffmpeg

for i in Music/theLeSigh/*.mp3; do ffmpeg -hide_banner -loglevel panic  -re -i  "$i" -vn -c:a mp3 -f mp3 - < /dev/null; done |ncat -lk -p 8089

captured on: [2018-03-21 Wed 22:41]

man page number meanings   linux

MANUAL SECTIONS
    The standard sections of the manual include:

    1      User Commands
    2      System Calls
    3      C Library Functions
    4      Devices and Special Files
    5      File Formats and Conventions
    6      Games et. al.
    7      Miscellanea
    8      System Administration tools and Daemons

    Distributions customize the manual section to their specifics,
    which often include additional sections.

captured on: [2018-05-24 Thu 23:18]

P2P application using (E, Xor) as a metric set   toread

Emacs Lisp to automatically add, commit, and push when files change   emacs git

captured on: [2018-07-24 Tue 20:42]

Are makefiles Turing complete? - Stack Overflow   programming math

  • Note taken on [2018-07-01 Sun 12:42]
    so it turns out make files are turing complete, any language that can express a lambda function is turing complete, with Y-combinator you can make recursion.

captured on: [2018-07-01 Sun 12:42]

Yes, see this. Once you have lambda, it's all downhill from there.

Here is a plagiarized Fibonacci example

This should be enough to build a foundation for more generality (I've got to get back to work, or I'd play more.)

dec = $(patsubst .%,%,$1)

not = $(if $1,,.)

lteq = $(if $1,$(if $(findstring $1,$2),.,),.)
gteq = $(if $2,$(if $(findstring $2,$1),.,),.)
eq = $(and $(call lteq,$1,$2),$(call gteq,$1,$2))
lt = $(and $(call lteq,$1,$2),$(call not,$(call gteq,$1,$2)))

add = $1$2
sub = $(if $(call not,$2),$1,$(call sub,$(call dec,$1),$(call dec,$2)))
mul = $(if $(call not,$2),$2,$(call add,$1,$(call mul,$1,$(call dec,$2))))
fibo = $(if $(call lt,$1,..),$1,$(call add,$(call fibo,$(call dec,$1)),$(call fibo,$(call sub,$1,..))))
fact = $(if $(call lt,$1,..),.,$(call mul,$1,$(call fact,$(call dec,$1))))

numeral = $(words $(subst .,. ,$1))

go = $(or $(info $(call numeral,$(call mul,$1,$1)) $(call numeral,$(call fibo,$1)) $(call numeral,$(call fact,$1)) ),$(call go,.$1))

_ := $(call go,)

This prints out squares, fibonacci numbers and factorials. There appears to be a 16 bit limit on number sizes. Bummer.

bash - How to toggle xinput device prop - Ask Ubuntu   linux

captured on: [2018-02-01 Thu 06:46]

Toggle xinput device on or off with following bash script.

#!/bin/bash

device=13
state=`xinput list-props "$device" | grep "Device Enabled" | grep -o "[01]$"`

if [ $state == '1' ];then
  xinput --disable $device
else
  xinput --enable $device
fi

How to enable IP Forwarding in Linux - MDLog:/sysadmin   linux hacking networking

captured on: [2018-01-27 Sat 14:25]

sysctl -w net.ipv4.ip_forward=1

parameters - Skip download if files exist in wget? - Stack Overflow   linux wget

captured on: [2018-01-24 Wed 14:33]

The -nc, --no-clobber option isn't the best solution as newer files will not be downloaded. One should use -N instead which will download and overwrite the file only if the server has a newer version, so the correct answer is:

wget -N http://www.example.com/images/misc/pic.png

Then running Wget with -N, with or without -r or -p, the decision as to whether or not to download a newer copy of a file depends on the local and remote timestamp and size of the file. -nc may not be specified at the same time as =-=N.

-N, --timestamping: Turn on time-stamping.

linux - How do I mirror a directory with wget without creating parent directories? - Stack Overflow   linux wget

captured on: [2018-01-24 Wed 14:30]

mirror without parent directory

For a path like: ftp.site.com/a/b/c/d

-nH would download all files to the directory a/b/c/d in the current directory, and -nH --cut-dirs=3 would download all files to the directory d in the current directory.

Timeout a command in bash without unnecessary delay - Stack Overflow   linux

captured on: [2018-01-15 Mon 23:57]

#!/bin/sh 
( your\_command ) & pid=$! 
( sleep $TIMEOUT && kill -HUP $pid ) 2>/dev/null & watcher=$! 
wait $pid 2>/dev/null && pkill -HUP -P $watcher

antivirus - CLAMAV not working - Ask Ubuntu   linux

captured on: [2018-01-12 Fri 19:49]

The error message tells the tale: LibClamAV Error: cli_loaddbdir(): No supported database files found in /var/lib/clamav and Known viruses: 0

You need

clamav-freshclam - anti-virus utility for Unix - virus database update utility

Also ensure that user running the scan has read access to /var/lib/clamav.

mount - What is the fastest way to extract an ISO? - Unix & Linux Stack Exchange   linux

captured on: [2018-01-12 Fri 19:46]

you can do this by 7zip software:

sudo apt-get install p7zip-full

7z x iso_file.iso

on Fedora:

7za x iso_file.iso

Is IceCat that secure that I don't need the Tor Browser anymore? | Trisquel GNU/Linux - Run free!   privacy

captured on: [2017-12-21 Thu 23:36]

Q: is icecat replacement to tor browser ?

A: Allow to clarify.
RMS said he uses IceCat and Tor. Many people think that makes it OK. Well, maybe in a freedom perspective (one can argue that IceCat is more free than Firefox or Tor Browser, but from a user point of view they are the same). However from a security and privacy perspective, it is totally wrong.

Consider this: Tor hides your identity by making every user look the same. So, if you use a different browser (and there are many ways to know which browser you are using) you make yourself unique, and therefore easy to track and follow. I had already said that in another comment here in the forum.

Consider also this: the Tor Project has a team working on the Tor Browser everyday, to make it safe to use. You think they would spend resources like that if it was THAT easy? It's not. Browser fingerprint is a though subject and the Tor Browser has a lot of patches to make sure that you don't seem too unique. IceCat for example has LibreJS or whatever that is called. It is a MAJOR fingerprint issue. Maybe if everyone used it it would be ok, but as of right now I think not a lot of people do that.

Also consider this: Tor Browser has been aligning its releases with Firefox security releases to make sure that there are no open bugs an attacker might exploit. I don't know about IceCat release cycle, but check if they are fast enough putting out security updates.

Finally, I will have to advise everyone NOT to use IceCat with Tor, at least not if you need STRONG anonimity. If its just a matter of not wanting your ISP to know that you see funny cats online, that's ok. But the websites where you see funny cats have a good chance of knowing that its you. Well, at least knowing its the same person, even if they can't know who it is…

CPU frequency scaling - ArchWiki   linux

captured on: [2017-12-05 Tue 20:26]

How to scale, and what are scaling governors

Scaling governors

Governors (see table below) are power schemes for the CPU. Only one may be active at a time. For details, see the kernel documentation in the kernel source.

Governor Description
performance Run the CPU at the maximum frequency.
powersave Run the CPU at the minimum frequency.
userspace Run the CPU at user specified frequencies. p
ondemand Scales the frequency dynamically according to current load. Jumps to the highest frequency and then possibly back off as the idle time increases.
conservative Scales the frequency dynamically according to current load. Scales the begifrequency more gradually than ondemand.
schedutil Scheduler-driven CPU frequency selection http://lwn.net/Articles/682391/, https://lkml.org/lkml/2016/3/17/420.

Depending on the scaling driver, one of these governors will be loaded by default:

  • ondemand for AMD and older Intel CPU.
  • powersave for Intel CPUs using the intel_pstate driver (Sandy Bridge and newer).

Note: The intel_pstate driver supports only the performance and powersave governors, but they both provide dynamic scaling. The performance governor should give better power saving functionality than the old ondemand governor.

Warning: Use CPU monitoring tools (for temperatures, voltage, etc.) when changing the default governor.

To activate a particular governor, run:

# cpupower frequency-set -g governor

Note:

  • To adjust for only a single CPU core, append -c core_number to the command above.
  • Activating a governor requires that specific kernel module (named cpufreq_governor) is loaded. As of kernel 3.4, these modules are loaded automatically.

Alternatively, you can activate a governor on every available CPU manually:

# echo governor | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor >/dev/null

Tip: To monitor cpu speed in real time, run:

$ watch grep \"cpu MHz\" /proc/cpuinfo

Tuning the ondemand governor

See the kernel documentation for details.

Switching threshold

To set the threshold for stepping up to another frequency:

# echo -n percent > /sys/devices/system/cpu/cpufreq/<governor>/up_threshold

To set the threshold for stepping down to another frequency:

# echo -n percent > /sys/devices/system/cpu/cpufreq/<governor>/down_threshold

disable emacs asking following git symbolink   emacs

captured on: [2018-07-24 Tue 20:53]

Compile and link 32 program on 64 bit processor   programming lowlevel

This is the program from the PGU book:

.code32

.section .data

.section .text

.globl _start

_start:

        pushl $3
        pushl $2

        call power
        addl $8, %esp

        movl %eax, %ebx
        movl $1, %eax
        int $0x80

        power:
                pushl %ebp
                movl %esp, %ebp

                subl $4, %esp
                movl 8(%ebp), %ebx
                movl 12(%ebp), %ecx

                movl %ebx, -4(%ebp)

                power_loop_start:
                        cmpl $1, %ecx
                        je end_power

                        movl -4(%ebp), %eax
                        imull %ebx, %eax
                        movl %eax, -4(%ebp)

                        decl %ecx

                        jmp power_loop_start

                end_power:
                        movl -4(%ebp), %eax
                        movl %ebp, %esp
                        popl %ebp
                        ret


This will compile and link it

as --32 power.s -o power.o && ld -melf_i386 power.o -o power

captured on: [2018-07-27 Fri 18:23]

DONE The Jury Is In: Monolithic OS Design Is Flawed   toread

Stream ffmpeg using dash   linux

ffmpeg \
        -re \
        -loglevel error \
        -stream_loop -1 \
        -f concat \
        -safe 0 \
        -i /tmp/playlist \
        -vf "drawtext=\
                        fontfile=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf:\
                        text='%{gmtime\:%Y-%m-%d %T} UTC':\
                        fontcolor=white:\
                        x=(w-text_w)/2:y=128:\
                        box=1:boxcolor=black:\
                        fontsize=72,
                drawtext=\
                        fontfile=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf:\
                        text='REBROADCAST':\
                        fontcolor=white:\
                        x=(w-text_w)/2:y=16:\
                        box=1:boxcolor=black:\
                        fontsize=48" \
        -codec:v libx264 \
        -profile:v baseline \
        -pix_fmt yuv420p \
        -level 4 \
        -preset veryfast \
        -codec:a aac \
        -tune zerolatency \
        -f dash \
        -window_size 5 \
        -remove_at_exit 1 \
        /tmp/dash/live.mpd

How to make a self-hosted video livestream | Drew DeVault’s Blog captured on: [2018-08-26 Sun 19:31]

Download phrack zines   linux

wget -r -np  http://phrack.org/archives/tgz/
find . -name "*.tar.gz" -exec sh -c 'mkdir $(basename {}|cut -d . -f 1); tar xvf {} -C $(basename {}|cut -d . -f 1)' \;
hacker emblem