App-Cheats
view release on metacpan or search on metacpan
#
# Create threads and get return code
# Sending pattern as parameter (only one allowed)
# Thread ID is first parameter
int rc;
rc = pthread_create(&thread, NULL, send_thread, (void *) pattern );
pattern->tid = thread; // Save thread ID so we can later kill it (if needed)
if(rc) return; // Error
#
# Check return value
if(rc) sendlog("ERROR: return code from pthread_create() is %d", rc);
#
# Function is declared like this:
void *send_thread (void * args){
COMMAND_PATTERN* pattern = (COMMAND_PATTERN*) args; // Can use pattern normally
...
}
#
# Make sure to end the function with this:
# (it will exit the thread. don't use in main otherwise will get defunct/zombie process)
pthread_exit(NULL);
# Determine version and library used for threads
# NPTL - Native POSIX Threads Library # Threads share PID
# LinuxThreads # May be different PIDs (plus may other differences)
getconf GNU_LIBPTHREAD_VERSION # NPTL 2.7
#############################################################
## C,CPP - Debug
#############################################################
# Sleepy poll (debug,ddd,gdb,break)
# How to debug a progam
# Then after getting in using ddd, set wait_variable=0
int wait_variable = 1; while (wait_variable) sleep(1);
# Debug a UI program (DES,UI)
# Flags after --args are passed to the program
gdb progarm --args arg1 arg2
# Debug a c program given its pid (DES,UI)
gdb --pid 21620
gdb --pid `myps | grep snv | grep -v grep | awk '{print $4}'`
# gdb debugger navitation (commands,DES,UI)
(gdb) l[ist] # view code
(gdb) l[ist] main # view main code
(gdb) b[reak] main # Put a breakpoint at main()
(gdb) r[un] # start the program
(gdb) h[elp] all # View all help sections
(gdb) f[rame] # Show current line (line number and file)
(gdb) c[ontinue] # Continue to a breakpoint
(gdb) d[elete] # Delete all breakpoints
# View all functions in ddd (gdp,debugger)
info functions
# View entry point of executable program (OMS)
readelf -h omsGUI | grep "Entry point address"
# was: 0x80524a0
ddd <pid>
att <pid>
b * 0x80524a0
c
# Problem: Debugger (ddd,gdb) is ignoring my breakpoint and
# moving unto another function
# Answer: Add this line inside the function you want to breakpoint
# Note: Causes a segmentation fault SIGSEGV
*(char*)0 = 0;
# Set outer variable in bash shell (hack)
a=123; (gdb --batch-silent -ex "attach $$" -ex 'set bind_variable("a", "456", 0)'); echo $a
#############################################################
## C,CPP - Errors
#############################################################
# Error: Illegal deallocation of memory
//
// my.c:
// #include <stdio.h>
// #include <stdlib.h>
// #include <string.h>
//
// int main(int argc, char ** argv){
// char * str;
//
// if (argc>1) {
// str = (char *) malloc(10);
// }
//
// printf("Str: %s\n",str);
// free(str);
//
// return 0;
// }
//
// MAKE.bat
g++ my.c -o my.exe
# Try Catch in Cpp
# No throw means no catch
//
#include <iostream>
using namespace std;
int main(int,char**){
int n = 10;
int m = 0;
try {
// if( m == 0 ) throw "Division by zero condition!";
int val = n / m;
cout << "Divided: " << val << endl;
}
catch (...){
cout << "Caught error" << endl;
}
cout << "DONE" << endl;
return 0;
}
# Nested Try Catch in Cpp
#############################################################
## Linux Commands - xsel
#############################################################
# Use copy and paste on the command line.
sudo apt install xsel
alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'
#############################################################
## Linux Commands - xterm
#############################################################
# Resize window (Putty,xterm)
echo -e '\e[8;50;100t'
# Minimize the window for a few seconds, then restore it (Putty,xterm)
echo -e '\e[2t' && sleep 2 && echo -e '\e[1t'
# Move the window to the top/left corner of the display (Putty,xterm)
echo -e '\e[3;0;0t'
# Zoom the window (Putty,xterm)
echo -e '\e[9;1t'
# Bring the window to the front (without changing keyboard focus) (Putty,xterm)
echo -e '\e[5t'
Change the name of an xterm window to "string"
echo -ne "\033]2;string\007"
# Change the name of an xterm icon to "string"
echo -ne "\033]1;string\007"
# Change the name of an xterm icon and window to "string"
echo -ne "\033]0;string\007"
# Create alias to easily change the window name and icon name
# Must be run together!
set_title(){ echo -ne "\033]0;$@\007"; }
alias title='set_title'
# Get dimensions/size of a screen/xterm
xdpyinfo | grep dimensions
xrandr | grep '*'
# Get the size of an xterm window
xwininfo
# Get info about current xterm window
xdpyinfo
# Get size info of a named xterm window
xwininfo -name omsGUI_0_3
# Get info about an xterm window
xprop -id <window_id>
xprop -id 0x2400022
# Get position of the cursor
perl -e '$/ = "R";' -e 'print "\033[6n";my $x=<STDIN>;my($n, $m)=$x=~m/(\d+)\;(\d+)/;print "Current position: $m, $n\n";'
# Print how many columns and rows an xterm window uses for its screen size
tput cols
tput lines
reset
# Change fond/colors of an xterm window
RESTORE='\033[0m'
RED='\033[00;31m'
GREEN='\033[00;32m'
YELLOW='\033[00;33m'
VIOLET='\033[00;35m'
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
# (JQuery,Selectors,Other,Filters,Table
# 2,8)
:root
# Selects the target element indicated by the fragment identifier of the documents
# URI (JQuery,Selectors,Other,Filters,Table 2,8)
:target
# Selects only elements that are visible (JQuery,Selectors,Other,Filters,Table 2,8)
:visible
#############################################################
## JQuery - Serialize
#############################################################
# Encode/serialize a key=value using JQuery
obj = {key:"val", comment: "hey there äöü"}
$.param(obj)
#
# This works also, but above is nicer.
$('<input name="comment" value="hey there äöü">').serialize()
# Encode/serialize a key=value using JQuery
# Convert to object
#
function decode_data(data_raw) {
const data_obj = {};
data_raw
.split(/&/)
.forEach( (p) => {
[k,v] = p.split(/=/).map( n => decodeURIComponent(n) );
data_obj[k] = v;
});
return data_obj;
}
#############################################################
## JQuery - SVG
#############################################################
After adding an svg element with jquery, need to reflesh the element
(otherwise it will not render on the screen)
$('.svg_help').html($('.svg_help').html())
class SvgHelper {
// CSS SvgHelper
constructor() {
this.svg_def = {
svg_help: () => { return this.define_svg_help() },
svg_settings: () => { return this.define_svg_settings() },
svg_about: () => { return this.define_svg_about() },
};
this.svg_about_id = 1;
}
// CSS SvgHelper
define_svg_help() {
return $('<svg class="svg_help" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">').append(
$('<path d="M11 18h2v-2h-2v2zm1-16C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm0-14c-2.21 0-4 1.79-4 4h2c0-1.1.9-2 2-2s2 .9 2 2c0 2-3 1.75-3 5h2c0-2.25 3-2.5 3-5 0-2.21-1...
).get(0);
}
// CSS SvgHelper
define_svg_settings() {
return $('<svg class="svg_settings" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">').append(
$('<path d="M15.95 10.78c.03-.25.05-.51.05-.78s-.02-.53-.06-.78l1.69-1.32c.15-.12.19-.34.1-.51l-1.6-2.77c-.1-.18-.31-.24-.49-.18l-1.99.8c-.42-.32-.86-.58-1.35-.78L12 2.34c-.03-.2-.2-.34-.4-.34H8.4c-.2 0-.36.14-.39.34l-.3 2.12c-.49.2-.94.47-1.35....
).get(0);
}
// CSS SvgHelper
define_svg_about() {
const raw = (...).get(0);
//
// MUST create unique ids for this svg!
const html = raw.outerHTML
.replace(/(mask\s+id="[^"]+)(?=")/g, `$1-${this.svg_about_id}`) // mask id="clip-c" -> mask id="clip-c-UID"
.replace(/(mask="url\(#[^"]+)(?=\)")/g, `$1-${this.svg_about_id}`) // mask="url(#clip-c)" -> mask="url(#clip-c-UID)"
//
this.svg_about_id++;
//
return $(html).get(0);
}
// CSS SvgHelper
load(svg_class) {
const svg_elements = document.getElementsByClassName(svg_class);
if(!svg_elements)
return;
$(svg_elements).each( (index,svg) => {
svg.outerHTML = svgHelper.svg_def[svg_class]().outerHTML;
});
}
// CSS SvgHelper
load_all() {
for(let svg_class in this.svg_def){
this.load(svg_class);
}
}
// CSS SvgHelper
}
#############################################################
## JQuery - ToolTips
#############################################################
# JQuery ToolTip REQUIRE a title (some reason)
<div class="cell" data-data-details="my tip" title="">ABC2</div>
<script>
// Runs only when page has loaded
$(function() {
$( ".cell" ).tooltip({
content: function(event, ui) { return $(this).attr("data-details"); },
});
});
</script>
( run in 1.402 second using v1.01-cache-2.11-cpan-5735350b133 )