App-Cheats
view release on metacpan or search on metacpan
#
#############################################################
#############################################################
## ADB - OnePlus
#############################################################
# Connect to phone and fix file permissions. (oneplus)
adb shell
su
chmod 777 /data/data
#############################################################
## Android
#############################################################
# Copy android files over the network (like myPhoneExplorer)
sudo apt install syncthing
syncthing
# Launch "My Files" on Android.
am start -n 'com.sec.android.app.myfiles/.external.ui.MainActivity'
#############################################################
## Apache
#############################################################
# Start apache server web pages
sudo apachectl start
# Check status of apache server web pages
apachectl status
# Show apache settings as in config files
httpd -S
#############################################################
## Apt Mark
#############################################################
# Prevent certain packages from ever automatically
# upgrading or being removed.
apt-mark hold apksigner
#############################################################
## ASM
#############################################################
# Compile, link, and run assembly program on windows
nasm -fwin64 hello.asm && gcc hello.obj -o hello.exe && hello.exe
#############################################################
## Batch - Conditions
#############################################################
# If statement in windows 10 DOS (windows 10, command prompt)
if exist "C:\Program Files\Git\usr\bin\perl2.exe" (echo FOUND) else (echo not found)
# Batch check if file/folder exists (windows,dos)
set folder=D:\my\ncfile\dev\assets
echo %folder%
IF EXIST %folder% (
echo Yes;
echo 123;
) ELSE (
echo No;
echo 456;
)
# If else statement in windows 10 DOS (windows 10, command prompt)
if "%val%" == "-1" (
echo.
echo Error: No tool provided! tool="%tool%"
echo.
) else (
if "%val%" == "-2" (
echo.
echo Error: Tool "%tool%" is not found in the PATH!
echo.
) else (
echo.
echo Info: %tool% Version: %val%
echo.
)
)
#############################################################
## Batch - Files
#############################################################
# Find all folders (directory)
dir E:\*.* /s /b /ad
# Recursively search through files
findstr /s /c cell *js
#############################################################
## Batch - Foreach Loop
#############################################################
# Windows 10 dos command prompt for each loop
for %a in (path-a, path-b, path-c) do (@echo %a)
#
# Use %%a inside a script (%a on the command line)
for %%a in (
path-a,
path-b,
path-c
) do (
@echo "[%%a]"
)
#############################################################
## Batch - Functions
#############################################################
# It is necessary to "call" each inner batch script
# Otherwise only the first will run.
call myProgram1
call myProgram2
# Create and call a function (Windows,DOS,Functions)
call :my_func
call :my_func
goto :eof
::
:my_func
echo.
echo hey
echo.
exit /b
# Create and call a function with arguments (Windows,DOS,Functions)
call :my_func 1
call :my_func 2
goto :eof
::
:my_func
echo hey %1
exit /b
# Create and call a function with arguments (Windows,DOS,Functions)
# Remove quotes using %~1 syntax
call :my_func "1"
call :my_func "2"
goto :eof
::
:my_func
echo hey %~1
exit /b
# Return a value from a function (Windows,DOS,Functions)
call :my_func "1" val
echo val1: %val%
goto :eof
::------------------------------------------------
:: Functions Section
::------------------------------------------------
:my_func
echo hey %~1
set %~2=INFO
exit /b
# Local (my) variables in a function (Windows,DOS,Functions)
call :my_func "1" val
echo val1: %val%
echo key: %key%
goto :eof
::------------------------------------------------
:: Functions Section
::------------------------------------------------
:my_func
SETLOCAL
set key=not
echo hey %~1
set %~2=INFO
ENDLOCAL
exit /b
# Template (Windows,DOS,Functions)
:get_dir
::
SETLOCAL
set key=%1
set val=
::
for /f "tokens=*" %%a in ('perl get_setup.pl %key%') do set val=%%a
if "%val%" == "" (
echo.
echo Error: Cannot determine %key%!
echo.
)
::
(ENDLOCAL & REM
set "%~2=%val%"
)
goto :eof
#############################################################
## Batch - Shell Substitution
#############################################################
# Shell substitution in Windows
@echo off
for /f "tokens=*" %%A in ('perl -x -S -l %0 %*') do set my_path=%%A
echo Going to : %my_path%
cd %my_path%
#############################################################
## Batch - Strings
#############################################################
# Remove double quotes from a variable in dos (windows 10, command prompt)
set a="here is data"
set a=%a:"=%
echo %a%
# Split long commands unto multiple lines (windows 10,caret)
long command^
can be split^
this this
#############################################################
## Batch - Terminal
#############################################################
# Change the title of the command prompt window
title MY_TITLE
# Change the dimentions/size of a commmand prompt window (length,width)
mode con: cols=80 lines=10
# Temporarily chang ethe command prompt language to english
set LANG=US
# Enable ANSI colors in Windows 10 using system '' (magic!?)
perl -E "system ''; say qq(\033[35mHEY\033[0m)"
# Terminator config location
/home/tim/my/git/otrs/SETUP/terminator/config
#############################################################
## Bison/Flex Parsing (Regex)
#############################################################
# Good tutorial
https://aquamentus.com/flex_bison.html
# Simple Lexer
%{
#include <iostream>
using namespace std;
extern int yylex();
%}
/*
Compile:
win_flex --outfile=mylex.cpp --wincompat my.l && ^
g++ mylex.cpp -o my.exe
Run:
echo "this is test 123" | my.exe
*/
%option noyywrap
%%
[ \t\n]
[0-9]+\.[0-9]+ { cout << "Float: " << yytext << endl; }
[0-9]+ { cout << "Number: " << yytext << endl; }
[A-Za-z0-9]+ { cout << "String: " << yytext << endl; }
. { cout << "Any: " << yytext << endl; }
%%
int main (int argc, char **argv) {
while( yylex() );
return 0;
}
# Info (flex,bison,parse,regex)
# Flex (and Bison) use a Determinitistic Finite Automata (DFA) regex engine.
# Notes on this engine:
# 1. No look arounds (for the most part). These is LALR and GLR.
# a. LALR - Look Around Left Right with one character of look ahead.
# Faster.
# b. GRL - General Left Right. Slowly but more powerful.
# 2. If multiple patterns can match a string selected pattern (winner) is:
# a. Longest string.
# This means that the order of the pattern does not matter. can do this
# and "CMD" will instead of just "C":
. {...}
CMD {...}
# b. Leftmost if multiple patterns of the same length.
# That is why the last pattern should be a simple dot otherwise it may
# match when not intended. plus very hard to detect this bug.
# 3. Use quotes for literal strings
"CMD"
#############################################################
## Linux Commands - mountpoint
#############################################################
# Check if a directory is mounted
mountpoint /media/tim/OTRS_BACKUP/ -q && echo "mounted"
#############################################################
## Linux Commands - netstat
#############################################################
# Display a table of all network interfaces
netstat -i
# Display summary statistics for each protocol
netstat -s
# View all network traffic for OMS
netstat -anpe | grep oms
# View routing table (Debug,pi,IP addresses)
netstat -r
netstat -rn # No DNS lookup
#############################################################
## Linux Commands - nmon
#############################################################
# Monitor overrun processes (DES,UI)
sudo apt-get install nmon
#############################################################
## Linux Commands - nslookup (dig)
#############################################################
# Convert network address to name like DNS
nslookup 1.1.1.1
host sapbr01
# Find DNS servers
nslookup
> lserver
#############################################################
## Linux Commands - passwd, chpasswd, vipw, gpasswd
#############################################################
# Reset/Change a users password (admin)
Log unto fs
sudo passwd xbexxxx
asdf1234
asdf1234
sudo make -C /var/yp
# Change root password
sudo passwd root
# Reset password in a script with no prompt (change)
# Can only supply one user to "passwd"
echo asdf1234 | sudo passwd xbe4092 --stdin; sudo make -C /var/yp
echo -e "xbe4092:asdf1234\npotapov:asdf1234" | sudo chpasswd; sudo make -C /var/yp
# Reset password over ssh (change,admin)
ssh -qtY potapov@lnxbrfs01 'echo -e "xbe4092:asdf123\npotapov:asdf123" | sudo /usr/sbin/chpasswd; sudo make -C /var/yp'
sb fs1 'echo -e "xbe4092:asdf123\npotapov:asdf123" | sudo /usr/sbin/chpasswd; sudo make -C /var/yp'
# Reset password of many users (admin,change)
echo "xbe4092:asdf1234" | sudo chpasswd
sudo make -C /var/yp
# Edit the password file. Disable/Lock user accounts before deleting
# Change /bin/bash to /bin/false
# Asterisk in password field disables account
sudo vipw
sudo make -C /var/yp
# Check if specific user account is:
# L - Locked
# NP - No Password
# P - Password is set (OK)
sudo passwd -S SOME_USER
# Check all user accounts if:
# L - Locked
# NP - No Password
# P - Password is set (OK)
sudo passwd -Sa
# Remove user from a group (delete, passwd)
Log unto fs01
sudo gpasswd -d potapov controls
sudo make -C /var/yp
#############################################################
## Linux Commands - pidof
#############################################################
# Process ID of a program (PID)
pidof omsCommand
#############################################################
## Linux Commands - ps
#############################################################
# Kill the ui when things aren't working
ps -ef | grep ui
# See all users on the bench
ps -elf | grep ui
# Show which processes were started by the current user
ps -elf | grep $USER
# Kill unigraph process if it is running in the background
ps -elf | grep unigraph | perl -anle '`skill -KILL $F[3]`'
# Be more specific in process selection (ps) options
ps -o user,ucmd --no-heading -C ui
# Currently running process (use in a script such as getinfo.sh)
ps -elf | grep getinfo.sh | grep -v grep | grep -v $$
# Check if puppet is running on all the benches
run_on_all_benches.pl 'ps -elf | grep puppet | grep -v grep'
# Check if systemd or init is used
ps -p 1
#############################################################
## Linux Commands - rcs
#############################################################
# Unlock a file
co -u file
# RCS error: file is in use
rm -f RCS/,file_name
# RCS error: file locked by pwxxxx
rcs -U file
# RCS: check in a file initially without the prompt message
ci -t-msg tiny2_rcs.tst
#############################################################
## Linux Commands - read
#############################################################
# Read input from the keyword/user without showing the password (much easier in bash)
read -s pass; echo "got [$pass]"
read -s -p "Password:" pass; echo; echo "got [$pass]"
# Read input from the keyword/user without showing the password. Limit password length
read -s -n 5 -p "Password:" pass; echo; echo "got [$pass]"
#############################################################
## Linux Commands - reptyr
#############################################################
# Attach to a running process on the existing terminal
sudo apt-get install reptyr
#############################################################
## Linux Commands - rsnapshot
#############################################################
# Install rsnapshot on centos
yum install epel-release
yum install rsnapshot
# Check if rsnapshot configuration file is valid
rsnapshot configtest
# Show the command that would be executed
rsnapshot -t daily
rsnapshot -t weekly
#############################################################
## Linux Commands - rsync
#############################################################
# Copy/Sync entire directories
rsync -avh FROM TO
# Copy/sync a file while preserving the folder structure.
rsync -avz --relative FROM/file TO
# Show what rsync would do with actually doing it.
rsync -avh --dry-run FROM TO
rsync -avh -n FROM TO
# Copy/Sync entire directories (OnePlus Backup)
time rsync \
-ah \
--info="progress2" \
--stats \
--delete \
--delete-delay \
TEAL='\033[00;36m'
GREY='\033[00;37m'
# View color ansi escapes with less (like Vim)
less -R file
# Make xterm text color bold
BOLD='\033[1m'
# Make xterm text color blink
BLINK='\033[5m'
# Move mouse to a specific location on the screen/xterm window (on lnxbr42)
xdotool mousemove 764 11
# Click on a button (cannot on top bar , like the X for close)
xdotool click 1
# Get mouse location
xdotool getmouselocation
# Move mouse to a location and click at the same time
xdotool mousemove 1747 30 click 1
# print contents of X events (mouse activity/movement)
xev
# Install xdotool dependencies
sudo apt-get install libxcb-xtest0:i386 libxcb-xtest0-dbg:i386 libxcb-xtest0-dev:i386
dpkg -l | grep xtest
# Other xdotool dependenacies
sudo aptitude install
# install xdotool from repository
cd ~junk/xdo/xdotool-master
sudo make install
# Check dependencies of a debian package
dpkg -I xdotool_3.20160512.1-1_i386.deb
# Install package from source (.deb)
sudo dpkg -i xdotool_3.20160512.1-1_i386.deb
sudo apt-get install -f
# Launch an xterm window into a certain directory
xterm -e 'cd ~/dsu && /bin/bash'
xterm -fg White -bg Black -sl 10000 -fn a14 -geometry 84x51+1722-78 -title "sre2bin" -e 'cd ~/dsu && /bin/bash'
xterm -fg White -bg Black -sl 10000 -fn a14 -geometry 84x51+1722-78 -title "sre2bin" -e 'cd ~/dsu; /bin/bash'
xterm -fg White -bg Black -sl 10000 -fn a14 -geometry 84x51+1722-78 -title "sre2bin" -e 'cd ~/dsu; bash'
# Check if xterm environment is working (Added: 2017-11-02 03:56:18 PM)
xeyes
# Check what kind of terminal I am using (xterm,bench)
echo $TERM
# Wrap long lines unto next row in bash/linux
# Exclose PS1 in '\[PS1_VALUE\]'
# Function which run on each prompt.
PROMPT_COMMAND=__prompt_command
__prompt_command ()
{
local EXIT="$?";
PS1=$_PS1;
if [ $EXIT != 0 ]; then
PS1+=$RED$'\u2716'$RESTORE
else
PS1+=$GREEN$'\u279c'$RESTORE
fi;
PS1+=" "
}
#############################################################
## Linux Commands - xxd
#############################################################
# Convert a binary file to hex
xxd NVM_EDF_CHA.dat > tmp_file
# Convert a hex file to binary
xxd -r tmp_file > tmp.bin
# Open a binary file in hex with vim
vi <(xxd tmp.bin)
#############################################################
## Linux Commands - ypcat
#############################################################
# View password file on main server (yellow page cat)
ypcat passwd
# Add ypcat passwd command if missing
vi /var/yp/nicknames
# add entry: passwd passwd.byname
# Return users which are found in the yellow pages password file
cat user_deletion_list | perl -ne 'print `ypcat passwd | grep $_` ' > found_in_yp
# Remove/Delete a user account
1. Check username in Outlook (CTRL-K)
2. Check username in Yellow Pages (ypcat passwd | grep username)
3. Go to file server
sudo userdel -r username # -r does this: sudo rm -rf username
sudo make -C /var/yp
#############################################################
## Linux Commands - yppasswd
#############################################################
# Change your password
yppasswd
#############################################################
## Linux Commands - zero
#############################################################
# Revert untracked changes
git checkout -- *
# Checkout a single file form another branch,
git checkout MY_BRANCH -- MY_FILE
# Remove untracked files and directories
git clean -fd
# Remove untracked files and directories (úsing not standard ignore rules)
git clean -xfd
# Stop tracking a certain file (will NOT remove file, forget)
git rm --cached file1
# Stop tracking a certain directory (will NOT remove directory, forget)
git rm --cached -r directory1
# fatal: Pathspec 'dir1' is in submodule 'dir2'
# Due to subdirectory having it's own .git
# Need to remove .git in subdirectory and recreate subdirectory
#############################################################
## Git - Diff Commands
#############################################################
# View changes between staged and branch
git diff --staged
# View whitespace changes
git diff --check
# View changes between playground and branch master
git diff HEAD
# View the last change made to a file (diff)
git diff file
# Show difference between 2 different commits
git diff <commit> <commit> <file>
# Show differences between 2 commits (relative to each other)
git diff <commit> <commit>~1 <file>
# Show a summary of differences between 2 commits (relative to each other,only filenames)
git diff --stat <commit> <commit>~1
# Compare 2 files in the same branch (need to disambiguate from 2 branches)
git diff :old :new
git diff :old new
# Compare exceptions template files for differences
cat ~/junk/exceptions | while read n; do ls -l $n~ $n; done
cat ~/junk/exceptions | while read n; do diff $n~ $n -qs; done
cat ~/junk/exceptions | while read n; do git diff $n~ $n; done
# Setup vimdiff as the default difftool
git config --global diff.tool vimdiff
git config --global difftool.prompt false
# Use vimdiff for seeing changes in git
git difftool commit1 commit2 file
# Ignore whitespace
git diff -w
#############################################################
## Git - Apply Commands
#############################################################
# Create a patch file.
git diff > my.patch
# Apply a patch file.
git apply my.patch
# Revert a patch file.
git apply my.patch -R
#############################################################
## Git - Commit/Checkout Commands
#############################################################
# Commit files to the branch
git commit -m "new file"
# Commit files to the branch and auto remove any extra files
git commit -a -m "new file"
# Update/change a commit message.
git commit --amend -m <useful commit message>
git push --force <origin> <branch>
# Reset files to last commit (file is not changed if in staging area)
git checkout -- file1
# No more options after command (used incase branch named file1 exists)
--
# Checkout a particular commit for a signle file
git checkout <commit> <file>
# Messed up in a commit. Checkout so many commits back
git checkout <commit>~1 <file>
# Checkout a remote branch (tracked,co)
git checkout --track origin/my_branch
# Revert the last command which was NOT pushed out.
git reset --soft HEAD~1
# Revert the last command which was pushed out.
git revert <commit>
git push
#############################################################
# SYSTEM is the account used by the operating system to run services,
# utilities, and device drivers. This account has unlimited power and access
# to resources that even Administrators are denied, such as the Registry's SAM.
#
# Administrators can do just about everything a user would want to do with
# Windows, typically this includes the first user you create with windows.
# You are probably a member of this group.
#
# Users are accounts with lower permissions, and typically require an Administrator
# to enter their password to do anything that would bring up a UAC console in
# Windows. You can create accounts with these permissions (I do it for my
# guest account) with the "Add Remove User Accounts" menu in the Control Panel.
# Find out who have a file opened
# Need to have this setup one time (as admin)
openfiles.exe /local on
# restart PC
#############################################################
## Windows - Outlook
#############################################################
# Windows Outlook.
# Monospaced font
Courier New
#############################################################
## Windows - Registry
#############################################################
# Registry file location on windows 10
C:\Users\<USER>\NTUSER.DAT
# Script to update the windows registry
#
@echo off
echo.
cd ..
reg add HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\MY_PATH /t REG_SZ /v AppPath /d %cd% /f
echo.
echo AppPath = %cd%
echo.
pause
# Dump windows 10 registry to a file (query,view,search)
reg export "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\MY_PATH" my.reg
reg export "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\MY_PATH" my.reg /y
# Enable Restore Points in Windows 10
Win + r
Type: regedit
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\SystemRestore
Double - Click "DisableSR"
1 - Disabled
0 - Enabled
#
# Restart PC for changes to take effect.
# Add the "Open command window here" option back to windows 10 commamd prompt (registry,DOS)
# when doing right click.
#
# Go to the regestry
Win + r
type: regedit
#
# For these paths:
Computer\HKEY_CLASSES_ROOT\Directory\shell\cmd
Computer\HKEY_CLASSES_ROOT\Directory\background\shell\cmd
#
# Update permissions:
- Right-click the PowerShell (folder) key, and click Permissions.
- Click the Advanced button.
- On "Advanced Security Settings," click the Change link next to "Owner".
- Type your account name in the provided field, click Check Names to verify
you're typing the account name correctly, and click OK.
- Check the Replace owner on subcontainers and objects option.
- Click Apply.
- Click OK.
- On "Permissions," select the Administrators group.
- Under "Permissions for Administrators," select Allow for the Full Control option.
- Click Apply.
- Click OK.
#
# Show option:
- Inside the cmd (folder) key, right-click the HideBasedOnVelocityId DWORD,
and click Rename.
- Change the DWORD name from HideBasedOnVelocityId to ShowBasedOnVelocityId,
and press Enter.
#
# Hide option (undo the change):
- rename the DWORD from from ShowBasedOnVelocityId to HideBasedOnVelocityId
#############################################################
## Windows - Variables
#############################################################
# Get windows script directory (DOS,pwd,windows vars)
echo %~dp0
# Start in currect script directory (windows vars)
cd /d %~dp0
#############################################################
## Windows Commands - ipconfig
#############################################################
# Internet not working on Windows
# Disable all adapters, but Ethernet 2.
# Then:
ipconfig /renew
ipconfig /release
# Enable the adapters again.
#############################################################
## Windows Commands - net
#############################################################
( run in 2.372 seconds using v1.01-cache-2.11-cpan-6aa56a78535 )