App-Cheats
view release on metacpan or search on metacpan
# Turn c code into assembler code
objdump -d <bin_file>
# In C code, pointers and arrays are closely related:
int var[] = {10, 100, 200};
int *ptr = var;
# &ptr is bfbab19c
# &var is bfbab1a0
# ptr is bfbab1a0
# var is bfbab1a0
# &ptr[0] is bfbab1a0
# &var[0] is bfbab1a0
# In C code, array name, address of array name, and
# address of first array element are all the same
var is bffddf20
&var is bffddf20
&var[0] is bffddf20
# Array of pointer in c code
# Array of strings
char *name[] = {
"name1",
"name2",
"name3",
"name4",
"name5",
"name6",
};
# Read from the command line in c code
int main(int argc, char *argv[])
# Process command line inputs in c code
#include<stdio.h>
int main(int argc, char *argv[]){
int i;
for(i=0; i<argc; i++){
printf("argv[%d]: %s\n", argc, argv[i]);
}
return(0);
}
# Get ascii and characters in c code (DES)
printf("d:%d c:%c\n", 'A', 'A');
# Rename the oms trace files
ls -1 | perl -lpe '$o=$_; s/_[c0][a-z0-9]*_\d+//; rename $o => $_'
# Call C++/CPP function from C Step 1(OMS)
# Put code inside:
#ifdef __cplusplus
# // c++ code goes here
#endif
# Call C++/CPP function from C Step 2(OMS)
# Make external the function
extern "C" void my_func(void);
# Macro function in c code (OMS,bison,flex)
#define DEBUG 1
#define PRINT_IN_DEBUG(token) if(DEBUG){ cout << " Flex saw [" << yytext << "] (" << token << ")" << endl; }
# Use value from a string.
# Convert "std:string" to "const char *"
std::string name
name.c_str()
# Convert "std:string" to "char *"
std::string name
&name[0u]
# Read lines from a file (c program)
char *file_name = strcat(name, ".cmd");
char line[512];
FILE *fp;
fp = fopen(file_name, "r");
if(fp == NULL)
{
sendlog("ERROR: Could not open file: '%s'", file_name);
return 1;
}
while (fgets( line, sizeof(line), fp ) != NULL)
{
line[strlen(line) - 1] = '\0';
sendlog("Line1: '%s'", line);
yyParseAndExecute( line );
}
# The -m32 flag is necessary for both compiling and linking (gcc,DES)
# Sample C program. Prints to STDOUT and STDERR
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
fprintf(stderr, "Select folder:\n");
fprintf(stderr, "1 C:\\TOOLS\n");
fprintf(stderr, "2 C:\\BAT\n");
printf("C:\\TOOLS\n");
fprintf(stderr, "3 C:\\BAT2\n");
return 0;
}
# Fix Error: forbids converting a string constant to 'char*'
argv[1] = (char *) "name = bob";
#############################################################
## C,CPP - Options/Environmental Variables
#############################################################
# C,CPP - Options/Environmental Variables
C_INCLUDE_PATH - Additional directories to
search for C header files.
LIBRARY_PATH - Additional directories to
search for libraries during
linking.
LD_LIBRARY_PATH - Additional directories to
search for shared libraries
at runtime.
# Create an abbreviation (Vim)
# Expands in insert mode after typing "TIM "
:ab TIM Time Is Money
# View all abbreviations set (Vim)
:ab
# View value for an abbreviation (Vim)
:ab TIM
# Remove abbreviation (Vim)
:unab TIM
#############################################################
## Vim Map Command Keys
#############################################################
# View mapped commands (Vim)
:map
# Create a mapping of commands for a particular key (Vim)
# Key 'q' will go down 5 lines and make a new line
:map q 5jo
# Reverse this and the following word (Vim,2 words,demo)
:map r wBdwelpBB
# Move word to the right (Vim)
:map gr "xdiwdwep"xpb
# Move word to the left (Vim)
:map gl lbgr
# Put html markers around a word (Vim)
:map + i<I>^[ea</I>^[
# Make the backslash a map leader (Vim,portable)
# Use leaders for global plugins.
:let mapleader = "\\"
:nnoremap <leader>d dd # Same as:
:nnoremap \d dd
# Make the dash a map local leader (Vim,portable)
# Use local leaders for filetype plugins.
:let maplocalleader = "-"
:nnoremap <localleader>d yyp # Same as:
:nnoremap -d dd
# Create a multiline Vim mapping
nnoremap <leader>r O
\<CR>use v5.32;
\<CR>use Mojo::Util 'dumper';
\<CR>use Carp qw( croak confess carp cluck );
\<CR>say "var: ", dumper $var;
\<CR><ESC>
#############################################################
## Vim Record Macros
#############################################################
# Record a new macro (Vim)
qa # Start recording. Will be put in register "a".
... # Run any commands.
q # Stop recording.
# View recorded macros (Vim)
# ^[ is ESC key
:reg
:reg a
# Replay a macro (Vim,run)
@a
# Replay last macro (Vim,run)
@@
# Repeat movement and commands (Vim)
qq;.q # next, repeat command
11@q # run 11 times
# Number a list of lines (Vim)
:let @c=0 # set value of register (preload)
:let @n=0i^R=^Rc+1^M. ^[0"cywj^[ # will not work with control characters
# Run macro commands in parallel (Vim)
:let @a='0f.r)w~' # load macro
<Shirt> + V + G # Select current line to end
:normal @a # run macro on lines
# Select desired lines in file and run macro on them (Vim,global)
:g /^sched_args/ :normal @c
# Append to existing register (Vim,typo)
qa # start original macro
... # commands
q # stop recording
qA # Captial means append to register "a"
... # Fix typo
q # End
# Indent the description section in primitives_doc file (Vim)
# This commands finds any problems
:g/^\v Syntax:.*\n\n/ .+2,/^\v [a-zA-Z]+:/-2p
#
# This will transform.
# 1. Find all "Syntax:" lines.
# 2. Assume next is blank, so start 2 lines down "+2".
# 3. Search for the next section and end 2 above that "-2".
# 4. Strip any leading space and replace with 6 spaces.
# 5. Strip trailing whitespace.
g/^\v Syntax:.*\n\n/ .+2,/\v^ [a-zA-Z]+:/-2 s/^\v\s*(\S+)@=/ / | s/\s\+$//
#############################################################
## Vim Folding
#############################################################
# Manually fold a sectin (Vim)
( run in 2.140 seconds using v1.01-cache-2.11-cpan-2398b32b56e )