### Bundle Install Workflow Examples
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/man/bundle-update.1.txt
Illustrates the recommended workflow for managing gems using Bundler, covering initial installation, locking dependencies, updating gems, and handling deployment scenarios.
```bash
# Initial setup and installation
$ bundle install
# Committing lock file to version control
$ git add Gemfile.lock
# Installing on another development machine
$ bundle install
# Installing on a deployment machine
$ bundle install --deployment
# After changing Gemfile
$ bundle install
$ git add Gemfile.lock
# Manually updating specific gems
$ bundle update rails thin
# Updating all gems to latest possible versions
$ bundle update --all
```
--------------------------------
### Minitest Unit Tests Example
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/gems/minitest-5.13.0/README.rdoc
Demonstrates how to define unit tests using Minitest::Test. It includes setup, assertion examples, and skipping tests. Requires 'minitest/autorun'.
```ruby
require "minitest/autorun"
class TestMeme < Minitest::Test
def setup
@meme = Meme.new
end
def test_that_kitty_can_eat
assert_equal "OHAI!", @meme.i_can_has_cheezburger?
end
def test_that_it_will_not_blend
refute_match /^no/i, @meme.will_it_blend?
end
def test_that_will_be_skipped
skip "test this later"
end
end
```
--------------------------------
### Build rubyc executable - Bash
Source: https://context7.com/pmq20/ruby-packer/llms.txt
This Bash script outlines the steps to build the `rubyc` executable from source code, install dependencies, and verify the installation. It covers cloning the repository, installing dependencies, building the executable using Rake, and moving the executable to a system-wide location. This is the initial setup step.
```bash
# Clone repository
git clone https://github.com/pmq20/ruby-packer.git
cd ruby-packer
# Install dependencies
bundle install
# Build rubyc using Rake
bundle exec rake rubyc
# This creates ./rubyc (or rubyc.exe on Windows)
# Move to PATH location
sudo mv rubyc /usr/local/bin/
# Verify installation
rubyc --version
```
--------------------------------
### Build and Install CRuby
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/doc/contributing.rdoc
These commands configure, build, and install the CRuby interpreter from source. It includes steps for generating configuration files, setting up a build directory, and specifying an installation prefix.
```shell
cd ruby-master
autoconf
mkdir build && cd build # its good practice to build outside of source dir
mkdir ~/.rubies # we will install to .rubies/ruby-master in our home dir
../configure --prefix="${HOME}/.rubies/ruby-master"
make up && make install
```
--------------------------------
### Ruby Packer Adds Getting Started Document
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/gems/test-unit-3.3.4/doc/text/news.md
Includes a new 'Getting Started' document for the Ruby Packer project. This document provides essential information for new users to quickly set up and begin using the tool.
```markdown
# This snippet represents a documentation addition, not executable code.
# Example content of a Getting Started document:
# # Welcome to Ruby Packer!
# ## Installation
# ```bash
# gem install ruby-packer
# ```
# ## Basic Usage
# ...
```
--------------------------------
### Share Test Code Across Minitest Classes with Modules
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/gems/minitest-5.13.0/README.rdoc
This example shows how to share setup or helper methods across different Minitest test classes using Ruby modules. It includes a module with a useful method and demonstrates including it in a test class. It also mentions the importance of calling `super` if using setup/teardown within modules.
```ruby
module UsefulStuff
def useful_method
# ...
end
end
describe Blah do
include UsefulStuff
def test_whatever
# useful_method available here
end
end
```
--------------------------------
### Build Example Binaries (CMake)
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/zlib/CMakeLists.txt
Creates executable targets for example programs ('example', 'minigzip', 'example64', 'minigzip64') using C source files. These executables are linked against the 'zlib' library. For the 'example64' and 'minigzip64' targets, a preprocessor definition is added to enable 64-bit file offset support.
```cmake
add_executable(example test/example.c)
target_link_libraries(example zlib)
add_test(example example)
add_executable(minigzip test/minigzip.c)
target_link_libraries(minigzip zlib)
if(HAVE_OFF64_T)
add_executable(example64 test/example.c)
target_link_libraries(example64 zlib)
set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
add_test(example64 example64)
add_executable(minigzip64 test/minigzip.c)
target_link_libraries(minigzip64 zlib)
set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
endif()
```
--------------------------------
### Pack a CLI Utility with rubyc
Source: https://github.com/pmq20/ruby-packer/blob/master/README.md
Provides an example of how to package a command-line interface (CLI) utility, using Ruby Packer's own 'bin/rubyc' script as an example. This requires cloning the repository first.
```bash
git clone --depth 1 https://github.com/pmq20/ruby-packer
cd ruby-packer
rubyc bin/rubyc
./a.out (or a.exe on Windows)
```
--------------------------------
### Install Bundler and Test-Unit Gems
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/gems/test-unit-3.3.4/doc/text/getting-started.md
Installs the 'bundler' gem for gem template generation and the 'test-unit' gem for the testing framework. These are essential prerequisites for the subsequent steps.
```bash
gem install bundler
gem install test-unit
```
--------------------------------
### Form Attributes Example with Colors (C)
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/ncurses/doc/html/NCURSES-Programming-HOWTO.html
An example demonstrating the initialization of curses, color pairs, fields, and forms. It shows how to set foreground and background attributes using color pairs and curses attributes, and how to handle user input for navigating between fields. This example requires the form library.
```c
#include
int main()
{ FIELD *field[3];
FORM *my_form;
int ch;
/* Initialize curses */
initscr();
start_color();
cbreak();
noecho();
keypad(stdscr, TRUE);
/* Initialize few color pairs */
init_pair(1, COLOR_WHITE, COLOR_BLUE);
init_pair(2, COLOR_WHITE, COLOR_BLUE);
/* Initialize the fields */
field[0] = new_field(1, 10, 4, 18, 0, 0);
field[1] = new_field(1, 10, 6, 18, 0, 0);
field[2] = NULL;
/* Set field options */
set_field_fore(field[0], COLOR_PAIR(1));/* Put the field with blue background */
set_field_back(field[0], COLOR_PAIR(2));/* and white foreground (characters */
/* are printed in white */
field_opts_off(field[0], O_AUTOSKIP); /* Don't go to next field when this */
/* Field is filled up */
set_field_back(field[1], A_UNDERLINE);
field_opts_off(field[1], O_AUTOSKIP);
/* Create the form and post it */
my_form = new_form(field);
post_form(my_form);
refresh();
set_current_field(my_form, field[0]); /* Set focus to the colored field */
mvprintw(4, 10, "Value 1:");
mvprintw(6, 10, "Value 2:");
mvprintw(LINES - 2, 0, "Use UP, DOWN arrow keys to switch between fields");
refresh();
/* Loop through to get user requests */
while((ch = getch()) != KEY_F(1))
{ switch(ch)
{ case KEY_DOWN:
/* Go to next field */
form_driver(my_form, REQ_NEXT_FIELD);
/* Go to the end of the present buffer */
/* Leaves nicely at the last character */
form_driver(my_form, REQ_END_LINE);
break;
case KEY_UP:
/* Go to previous field */
form_driver(my_form, REQ_PREV_FIELD);
form_driver(my_form, REQ_END_LINE);
break;
default:
/* If this is a normal character, it gets */
/* Printed */
form_driver(my_form, ch);
break;
}
}
/* Un post form and free the memory */
unpost_form(my_form);
free_form(my_form);
free_field(field[0]);
free_field(field[1]);
endwin();
return 0;
}
```
--------------------------------
### Huffman Code Example: Bit Lengths to Codes
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/zlib/doc/rfc1951.txt
Illustrates the process of converting a sequence of bit lengths into actual Huffman codes for a given alphabet. This example demonstrates the output of the Huffman code generation algorithm.
```table
Alphabet: ABCDEFGH
Bit Lengths: (3, 3, 3, 3, 3, 2, 4, 4)
After step 1 (bl_count):
N bl_count[N]
- -----------
2 1
3 5
4 2
Step 2 (next_code):
N next_code[N]
- ------------
1 0
2 0
3 2
4 14
Step 3 (Symbol, Length, Code):
Symbol Length Code
------ ------ ----
A 3 010
B 3 011
C 3 100
D 3 101
E 3 110
F 2 00
G 4 1110
H 4 1111
```
--------------------------------
### zlib deflate() and inflate() Example in C
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/zlib/examples/zlib_how.html
This C code snippet is an example of how to use zlib's deflate() and inflate() functions for file compression and decompression. It includes necessary header files and macros for handling binary data on different operating systems.
```c
/* zpipe.c: example of proper use of zlib's inflate() and deflate()
Not copyrighted -- provided to the public domain
Version 1.4 11 December 2005 Mark Adler */
/* Version history:
1.0 30 Oct 2004 First version
1.1 8 Nov 2004 Add void casting for unused return values
Use switch statement for inflate() return values
1.2 9 Nov 2004 Add assertions to document zlib guarantees
1.3 6 Apr 2005 Remove incorrect assertion in inf()
1.4 11 Dec 2005 Add hack to avoid MSDOS end-of-line conversions
Avoid some compiler warnings for input and output buffers
*/
#include
#include
#include
#include "zlib.h"
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include
# include
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
#else
# define SET_BINARY_MODE(file) /* void */
#endif
```
--------------------------------
### Forms Basics Example (C)
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/ncurses/doc/html/NCURSES-Programming-HOWTO.html
A C example demonstrating the basic usage of the forms library. It initializes curses, creates and posts form fields, handles user input for navigation and data entry, and cleans up resources.
```c
#include
int main()
{ FIELD *field[3];
FORM *my_form;
int ch;
/* Initialize curses */
initscr();
cbreak();
noecho();
keypad(stdscr, TRUE);
/* Initialize the fields */
field[0] = new_field(1, 10, 4, 18, 0, 0);
field[1] = new_field(1, 10, 6, 18, 0, 0);
field[2] = NULL;
/* Set field options */
set_field_back(field[0], A_UNDERLINE); /* Print a line for the option */
field_opts_off(field[0], O_AUTOSKIP); /* Don't go to next field when this */
/* Field is filled up */
set_field_back(field[1], A_UNDERLINE);
field_opts_off(field[1], O_AUTOSKIP);
/* Create the form and post it */
my_form = new_form(field);
post_form(my_form);
refresh();
mvprintw(4, 10, "Value 1:");
mvprintw(6, 10, "Value 2:");
refresh();
/* Loop through to get user requests */
while((ch = getch()) != KEY_F(1))
{ switch(ch)
{ case KEY_DOWN:
/* Go to next field */
form_driver(my_form, REQ_NEXT_FIELD);
/* Go to the end of the present buffer */
/* Leaves nicely at the last character */
form_driver(my_form, REQ_END_LINE);
break;
case KEY_UP:
/* Go to previous field */
form_driver(my_form, REQ_PREV_FIELD);
form_driver(my_form, REQ_END_LINE);
break;
default:
/* If this is a normal character, it gets */
/* Printed */
form_driver(my_form, ch);
break;
}
}
/* Un post form and free the memory */
unpost_form(my_form);
free_form(my_form);
free_field(field[0]);
free_field(field[1]);
endwin();
return 0;
}
```
--------------------------------
### Gemfile Configuration Example in Ruby
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/man/bundle-install.1.txt
Illustrates how to specify gem sources and dependencies within a Ruby Gemfile. It shows how to declare gem versions and sources, which Bundler uses to resolve project dependencies.
```ruby
source 'https://rubygems.org'
gem 'actionpack', '3.0.0.rc'
gem 'activemerchant'
```
--------------------------------
### Initialize and Use Curses Library in C
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/ncurses/doc/html/ncurses-intro.html
This C code snippet demonstrates the initialization and basic usage of the curses library. It includes setting up signal handling for graceful termination, initializing the curses environment, configuring terminal modes (non-line-buffered input, echoing), enabling color support if available, and setting up color pairs. The main loop continuously reads user input using `getch()` and applies color attributes based on a counter. The `finish` function is responsible for cleaning up the curses environment before exiting.
```c
#include
#include
#include
static void finish(int sig);
int
main(int argc, char *argv[])
{
int num = 0;
/* initialize your non-curses data structures here */
(void) signal(SIGINT, finish); /* arrange interrupts to terminate */
(void) initscr(); /* initialize the curses library */
keypad(stdscr, TRUE); /* enable keyboard mapping */
(void) nonl(); /* tell curses not to do NL->CR/NL on output */
(void) cbreak(); /* take input chars one at a time, no wait for \n */
(void) echo(); /* echo input - in color */
if (has_colors())
{
start_color();
/*
* Simple color assignment, often all we need. Color pair 0 cannot
* be redefined. This example uses the same value for the color
* pair as for the foreground color, though of course that is not
* necessary:
*/
init_pair(1, COLOR_RED, COLOR_BLACK);
init_pair(2, COLOR_GREEN, COLOR_BLACK);
init_pair(3, COLOR_YELLOW, COLOR_BLACK);
init_pair(4, COLOR_BLUE, COLOR_BLACK);
init_pair(5, COLOR_CYAN, COLOR_BLACK);
init_pair(6, COLOR_MAGENTA, COLOR_BLACK);
init_pair(7, COLOR_WHITE, COLOR_BLACK);
}
for (;;)
{
int c = getch(); /* refresh, accept single keystroke of input */
attrset(COLOR_PAIR(num % 8));
num++;
/* process the command keystroke */
}
finish(0); /* we're done */
}
static void finish(int sig)
{
endwin();
/* do your non-curses wrapup here */
exit(0);
}
```
--------------------------------
### Gemfile Example with Environment Groups
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/man/bundle-install.1.txt
This Gemfile defines a basic application using the 'sinatra' gem and includes a 'production' group with an additional gem, 'rack-perftools-profiler'. This demonstrates how to separate dependencies for different deployment environments.
```ruby
source 'https://rubygems.org'
gem 'sinatra'
group :production do
gem 'rack-perftools-profiler'
end
```
--------------------------------
### Curses: Get string from window
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/ncurses/doc/html/man/curs_inchstr.3x.html
These C functions retrieve a string of chtype quantities from a curses window, starting at the current cursor position or a specified position. They can return the entire string up to the window margin or a specified number of characters. The returned chtype can be further processed to extract character or attribute information.
```c
#include
int inchstr(chtype *chstr);
int inchnstr(chtype *chstr, int n);
int winchstr(WINDOW *win, chtype *chstr);
int winchnstr(WINDOW *win, chtype *chstr, int n);
int mvinchstr(int y, int x, chtype *chstr);
int mvinchnstr(int y, int x, chtype *chstr, int n);
int mvwinchstr(WINDOW *win, int y, int x, chtype *chstr);
int mvwinchnstr(WINDOW *win, int y, int x, chtype *chstr, int n);
```
--------------------------------
### Initialize ncurses and Handle User Input (C)
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/ncurses/doc/html/NCURSES-Programming-HOWTO.html
This C code demonstrates the initialization of the ncurses library, setting up input modes (raw, keypad, noecho), and handling user input, including special keys like F1. It also shows how to print formatted output and apply attributes like bold.
```c
#include
int main()
{ int ch;
initscr(); /* Start curses mode */
raw(); /* Line buffering disabled */
keypad(stdscr, TRUE); /* We get F1, F2 etc.. */
noecho(); /* Don't echo() while we do getch */
printw("Type any character to see it in bold\n");
ch = getch(); /* If raw() hadn't been called
* we have to press enter before it
* gets to the program */
if(ch == KEY_F(1)) /* Without keypad enabled this will */
printw("F1 Key pressed"); /* not get to us either */
/* Without noecho() some ugly escape
* charachters might have been printed
* on screen */
else
{
printw("The pressed key is ");
attron(A_BOLD);
printw("%c", ch);
attroff(A_BOLD);
}
refresh(); /* Print it on to the real screen */
getch(); /* Wait for user input */
endwin(); /* End curses mode */
return 0;
}
```
--------------------------------
### Ruby Minitest Plugin Initialization Example
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/gems/minitest-5.13.0/README.rdoc
Illustrates the structure for creating a Minitest plugin, including methods for processing command-line options and initializing the plugin's functionality.
```ruby
# minitest/bogus_plugin.rb:
module Minitest
def self.plugin_bogus_options(opts, options)
opts.on "--myci", "Report results to my CI" do
options[:myci] = true
options[:myci_addr] = get_myci_addr
options[:myci_port] = get_myci_port
end
end
def self.plugin_bogus_init(options)
self.reporter << MyCI.new(options) if options[:myci]
end
end
```
--------------------------------
### Bundler Gemfile Example with Overlapping Dependencies
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/man/bundle-update.1.txt
Demonstrates a Gemfile where two gems ('thin' and 'rack-perftools-profiler') depend on different versions of the same library ('rack'). Bundler resolves these overlapping dependencies during installation.
```ruby
source "https://rubygems.org"
gem "thin"
gem "rack-perftools-profiler"
```
--------------------------------
### Curses Inchstr API
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/ncurses/doc/html/man/curs_inchstr.3x.html
These routines return a NULL-terminated array of chtype quantities, starting at the current cursor position in the named window and ending at the right margin of the window.
```APIDOC
## Curses Inchstr Functions
### Description
These routines return a NULL-terminated array of chtype quantities, starting at the current cursor position in the named window and ending at the right margin of the window. The four functions with _n_ as the last argument, return a leading substring at most _n_ characters long (exclusive of the trailing (chtype)0).
### Methods
- `inchstr(chtype *chstr)`
- `inchnstr(chtype *chstr, int n)`
- `winchstr(WINDOW *win, chtype *chstr)`
- `winchnstr(WINDOW *win, chtype *chstr, int n)`
- `mvinchstr(int y, int x, chtype *chstr)`
- `mvinchnstr(int y, int x, chtype *chstr, int n)`
- `mvwinchstr(WINDOW *win, int y, int x, chtype *chstr)`
- `mvwinchnstr(WINDOW *win, int y, int x, chtype *chstr, int n)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
- `int` - The number of characters retrieved, exclusive of the trailing 0.
#### Response Example
```json
{
"return_value": "number_of_characters"
}
```
### Error Handling
- Returns `ERR` upon failure.
- If `chstr` is null, no data is returned, and the return value is zero.
- Functions with a "mv" prefix return an error if the position is outside the window, or if the window pointer is null.
```
--------------------------------
### C Help and Navigation Commands
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/readline/doc/readline.html
Implements help and navigation functionalities for a command-line interface. `com_help` displays documentation for specific commands or lists all available commands. `com_cd` changes the current directory using `chdir()`, and `com_pwd` prints the current working directory using `getcwd()`. `com_quit` sets a flag to exit the program.
```c
/* Print out help for ARG, or for all of the commands if ARG is
not present. */
com_help (arg)
char *arg;
{
register int i;
int printed = 0;
for (i = 0; commands[i].name; i++)
{
if (!*arg || (strcmp (arg, commands[i].name) == 0))
{
printf ("%s\t\t%s.\n", commands[i].name, commands[i].doc);
printed++;
}
}
if (!printed)
{
printf ("No commands match \`%s'. Possibilties are:\n", arg);
for (i = 0; commands[i].name; i++)
{
/* Print in six columns. */
if (printed == 6)
{
printed = 0;
printf ("\n");
}
printf ("%s\t", commands[i].name);
printed++;
}
if (printed)
printf ("\n");
}
return (0);
}
/* Change to the directory ARG. */
com_cd (arg)
char *arg;
{
if (chdir (arg) == -1)
{
perror (arg);
return 1;
}
com_pwd ("", "");
return (0);
}
/* Print out the current working directory. */
com_pwd (ignore)
char *ignore;
{
char dir[1024], *s;
s = getcwd (dir, sizeof(dir) - 1);
if (s == 0)
{
printf ("Error getting pwd: %s\n", dir);
return 1;
}
printf ("Current directory is %s\n", dir);
return 0;
}
/* The user wishes to quit using this program. Just set DONE non-zero. */
com_quit (arg)
char *arg;
{
done = 1;
return (0);
}
/* Function which tells you that you can't do this. */
too_dangerous (caller)
```
--------------------------------
### Ruby Block Comments - Indentation Error
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/doc/syntax/comments.rdoc
This example demonstrates a syntax error in Ruby block comments where '=begin' and '=end' are indented. Block comment markers must align to the start of the line.
```ruby
class Foo
=begin
Will not work
=end
end
```
--------------------------------
### Main routine for zlib compression/decompression utility
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/zlib/examples/zlib_how.html
The `main()` function serves as the entry point for the command-line utility. It handles command-line arguments to determine whether to perform compression or decompression. It sets stdin and stdout to binary mode, calls `def()` for compression (default) or `inf()` for decompression (if -d is specified), and uses `zerr()` to report any errors encountered. Usage instructions are displayed for invalid arguments.
```c
/* compress or decompress from stdin to stdout */
int main(int argc, char **argv)
{
int ret;
/* avoid end-of-line conversions */
SET_BINARY_MODE(stdin);
SET_BINARY_MODE(stdout);
/* do compression if no arguments */
if (argc == 1) {
ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION);
if (ret != Z_OK)
zerr(ret);
return ret;
}
/* do decompression if -d specified */
else if (argc == 2 && strcmp(argv[1], "-d") == 0) {
ret = inf(stdin, stdout);
if (ret != Z_OK)
zerr(ret);
return ret;
}
/* otherwise, report usage */
else {
fputs("zpipe usage: zpipe [-d] < source > dest\n", stderr);
return 1;
}
}
```
--------------------------------
### RSA Public Key for RSA-PSS-10
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/openssl/test/recipes/30-test_evp_data/evppkey.txt
This snippet provides the RSA public key in PEM format, associated with the RSA-PSS-10 verification scheme. This key is essential for verifying signatures generated under this specific cryptographic setup.
```pem
PublicKey=RSA-PSS-10
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApd2GesTLAvkLlFfUjBSn
```
--------------------------------
### Curses chgat() function example
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/ncurses/doc/html/NCURSES-Programming-HOWTO.html
Demonstrates the usage of the chgat() function in Curses to set attributes and color for a portion of the screen without moving the cursor. It initializes the curses mode, starts color functionality, defines a color pair, prints a string, applies attributes and color using mvchgat, and refreshes the screen.
```c
#include
int main(int argc, char *argv[])
{ initscr(); /* Start curses mode */
start_color(); /* Start color functionality */
init_pair(1, COLOR_CYAN, COLOR_BLACK);
printw("A Big string which i didn\'t care to type fully ");
mvchgat(0, 0, -1, A_BLINK, 1, NULL);
/*
* First two parameters specify the position at which to start
* Third parameter number of characters to update. -1 means till
* end of line
* Forth parameter is the normal attribute you wanted to give
* to the charcter
* Fifth is the color index. It is the index given during init_pair()
* use 0 if you didn\'t want color
* Sixth one is always NULL
*/
refresh();
getch();
endwin(); /* End curses mode */
return 0;
}
```
--------------------------------
### Hello World Program using NCURSES
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/ncurses/doc/html/NCURSES-Programming-HOWTO.html
A basic 'Hello World' program demonstrating the initialization of the ncurses library, printing a message to the screen, refreshing the display, waiting for user input, and properly ending the ncurses mode. This serves as a fundamental example for ncurses application development.
```c
#include
int main()
{
initscr(); /* Start curses mode */
printw("Hello World !!!"); /* Print Hello World */
refresh(); /* Print it on to the real screen */
getch(); /* Wait for user input */
endwin(); /* End curses mode */
return 0;
}
```
--------------------------------
### Package Gems Without Installing Locally
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/man/bundle-package.1.txt
Packages the dependencies into vendor/cache without installing them to the default local installation location. This separates the caching action from the installation process.
```shell
bundle package --no-install
```
--------------------------------
### Basic Usage of rubyc
Source: https://github.com/pmq20/ruby-packer/blob/master/README.md
Demonstrates the basic command-line syntax for using the rubyc executable to package Ruby applications. It specifies the general format and the role of the ENTRANCE_FILE.
```bash
rubyc [OPTION]... [ENTRANCE_FILE]
```
--------------------------------
### C: Get String from Curses Window
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/ncurses/doc/html/man/curs_instr.3x.html
These C functions retrieve a string of characters from a curses window starting at the current cursor position. They support reading a specified number of characters or the entire line until the right margin. Attributes are stripped from the characters. Functions with 'mv' prefix move the cursor first.
```c
#include
int instr(char *str);
int innstr(char *str, int n);
int winstr(WINDOW *win, char *str);
int winnstr(WINDOW *win, char *str, int n);
int mvinstr(int y, int x, char *str);
int mvinnstr(int y, int x, char *str, int n);
int mvwinstr(WINDOW *win, int y, int x, char *str);
int mvwinnstr(WINDOW *win, int y, int x, char *str, int n);
```
--------------------------------
### Setup with Yield for Resource Management in Ruby
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/gems/test-unit-3.3.4/doc/text/news.md
Illustrates a Ruby pattern for managing resources within a `setup` method, using `yield` to ensure proper cleanup. This approach is beneficial for handling files or other resources that require explicit closing or releasing. It's part of the test-unit framework's improvements.
```ruby
def setup
File.open("x") do |file|
@file = file
yield
end
end
```
--------------------------------
### Racc Start Rule Declaration
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/lib/racc/rdoc/grammar.en.rdoc
Shows how to change the start rule of the grammar using the 'start' keyword, which is equivalent to yacc's %start directive. This specifies the initial grammar rule the parser should expect.
```racc
start real_target
```
--------------------------------
### Make Benchmark Commands
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/benchmark/README.md
Illustrates how to use 'make benchmark' to automate the benchmarking process. This includes running benchmarks with the system Ruby and built Ruby, comparing specific Ruby binaries, targeting specific benchmark items, and passing custom options.
```bash
# Run all benchmarks with the ruby in the $PATH and the built ruby
make benchmark
# Or compare with specific ruby binary
make benchmark COMPARE_RUBY="/path/to/ruby --jit"
# Run vm1 benchmarks
make benchmark ITEM=vm1
# Run some limited benchmarks in ITEM-matched files
make benchmark ITEM=vm1 OPTS="--filter=block"
# You can specify the benchmark by an exact filename instead of using the default argument:
# ARGS = $$(find $(srcdir)/benchmark -maxdepth 1 -name '*$(ITEM)*.yml' -o -name '*$(ITEM)*.rb')
make benchmark ARGS=../benchmark/erb_render.yml
# You can specify any option via $OPTS
make benchmark OPTS="--help"
# With `make benchmark`, some special runner plugins are available:
# -r peak, -r size, -r total, -r utime, -r stime, -r cutime, -r cstime
make benchmark ITEM=vm2_bigarray OPTS="-r peak"
```
--------------------------------
### Install zlib Libraries, Headers, and Docs (CMake)
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/zlib/CMakeLists.txt
Defines installation rules for the built zlib components. It installs runtime files (DLLs), archive files (static libraries), library files, public headers, man pages, and pkg-config files to the specified installation directories. Installation is skipped if the corresponding SKIP_INSTALL_* variables are set.
```cmake
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
install(TARGETS zlib zlibstatic
RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )
endif()
if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}")
endif()
if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
install(FILES zlib.3 DESTINATION "${INSTALL_MAN_DIR}/man3")
endif()
if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}")
endif()
```
--------------------------------
### C Example: Basic Menu Creation and Interaction
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/ncurses/doc/html/NCURSES-Programming-HOWTO.html
This C code demonstrates the fundamental usage of the menu library to create a simple interactive menu. It initializes the curses screen, defines menu items, displays the menu, and handles user input for navigation (up/down) and exiting the menu. Key functions include initscr, cbreak, noecho, keypad, new_item, new_menu, post_menu, menu_driver, and endwin.
```c
#include
#include
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
#define CTRLD 4
char *choices[] = {
"Choice 1",
"Choice 2",
"Choice 3",
"Choice 4",
"Exit",
};
int main()
{ ITEM **my_items;
int c;
MENU *my_menu;
int n_choices, i;
ITEM *cur_item;
initscr();
cbreak();
noecho();
keypad(stdscr, TRUE);
n_choices = ARRAY_SIZE(choices);
my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));
for(i = 0; i < n_choices; ++i)
my_items[i] = new_item(choices[i], choices[i]);
my_items[n_choices] = (ITEM *)NULL;
my_menu = new_menu((ITEM **)my_items);
mvprintw(LINES - 2, 0, "F1 to Exit");
post_menu(my_menu);
refresh();
while((c = getch()) != KEY_F(1))
{ switch(c)
{ case KEY_DOWN:
menu_driver(my_menu, REQ_DOWN_ITEM);
break;
case KEY_UP:
menu_driver(my_menu, REQ_UP_ITEM);
break;
}
}
free_item(my_items[0]);
free_item(my_items[1]);
free_menu(my_menu);
endwin();
}
```
--------------------------------
### Pack a Rails Application with rubyc
Source: https://github.com/pmq20/ruby-packer/blob/master/README.md
Illustrates how to package a Ruby on Rails application into a single executable. This example assumes a new Rails application is created and then packaged using 'bin/rails'.
```bash
rails new yours
cd yours
rubyc bin/rails
./a.out server (or a.exe server on Windows)
```
--------------------------------
### Control Installation with bundle-add
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/man/bundle-add.1.txt
Provides an option to add a gem to the Gemfile without immediately running 'bundle install'. This is beneficial for making multiple modifications before a full installation.
```bash
bundle add GEM_NAME --skip-install
```
--------------------------------
### Execute Benchmark Driver with Ruby
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/benchmark/README.md
Demonstrates normal usage of the benchmark-driver command-line tool to run benchmark scripts. It shows how to specify Ruby executables, compare different Ruby versions using rbenv, collect various metrics, and use YAML for complex setups.
```bash
# Run a benchmark script with the ruby in the $PATH
benchmark-driver benchmark/app_fib.rb
# Run benchmark scripts with multiple Ruby executables or options
benchmark-driver benchmark/*.rb -e /path/to/ruby -e '/path/to/ruby --jit'
# Or compare Ruby versions managed by rbenv
benchmark-driver benchmark/*.rb --rbenv '2.5.1;2.6.0-preview2 --jit'
# You can collect many metrics in many ways
benchmark-driver benchmark/*.rb --runner memory --output markdown
# Some are defined with YAML for complex setup or accurate measurement
benchmark-driver benchmark/*.yml
```
--------------------------------
### Conditional Gem Installation with 'install_if' (Ruby)
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/man/gemfile.5.txt
Allows gems to be installed based on a provided proc or lambda, useful for optional gems with specific prerequisites. The block's condition determines whether the gems within it are installed.
```ruby
install_if -> { RUBY_PLATFORM =~ /darwin/ } do
gem "pasteboard"
end
```
--------------------------------
### C: Panel Moving and Resizing Example
Source: https://github.com/pmq20/ruby-packer/blob/master/vendor/ncurses/doc/html/NCURSES-Programming-HOWTO.html
Demonstrates moving and resizing panels using curses library functions. It utilizes user data to store panel information and allows interaction via keyboard input. Dependencies include the curses and panel libraries.
```c
#include
typedef struct _PANEL_DATA {
int x, y, w, h;
char label[80];
int label_color;
PANEL *next;
}PANEL_DATA;
#define NLINES 10
#define NCOLS 40
void init_wins(WINDOW **wins, int n);
void win_show(WINDOW *win, char *label, int label_color);
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
void set_user_ptrs(PANEL **panels, int n);
int main()
{ WINDOW *my_wins[3];
PANEL *my_panels[3];
PANEL_DATA *top;
PANEL *stack_top;
WINDOW *temp_win, *old_win;
int ch;
int newx, newy, neww, newh;
int size = FALSE, move = FALSE;
/* Initialize curses */
initscr();
start_color();
cbreak();
noecho();
keypad(stdscr, TRUE);
/* Initialize all the colors */
init_pair(1, COLOR_RED, COLOR_BLACK);
init_pair(2, COLOR_GREEN, COLOR_BLACK);
init_pair(3, COLOR_BLUE, COLOR_BLACK);
init_pair(4, COLOR_CYAN, COLOR_BLACK);
init_wins(my_wins, 3);
/* Attach a panel to each window */ /* Order is bottom up */
my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */
my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */
my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */
set_user_ptrs(my_panels, 3);
/* Update the stacking order. 2nd panel will be on top */
update_panels();
/* Show it on the screen */
attron(COLOR_PAIR(4));
mvprintw(LINES - 3, 0, "Use 'm' for moving, 'r' for resizing");
mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)");
attroff(COLOR_PAIR(4));
doupdate();
stack_top = my_panels[2];
top = (PANEL_DATA *)panel_userptr(stack_top);
newx = top->x;
newy = top->y;
neww = top->w;
newh = top->h;
while((ch = getch()) != KEY_F(1))
{ switch(ch)
{ case 9: /* Tab */
top = (PANEL_DATA *)panel_userptr(stack_top);
top_panel(top->next);
stack_top = top->next;
top = (PANEL_DATA *)panel_userptr(stack_top);
newx = top->x;
newy = top->y;
neww = top->w;
newh = top->h;
break;
case 'r': /* Re-Size*/
size = TRUE;
attron(COLOR_PAIR(4));
mvprintw(LINES - 4, 0, "Entered Resizing :Use Arrow Keys to resize and press to end resizing");
refresh();
attroff(COLOR_PAIR(4));
break;
case 'm': /* Move */
attron(COLOR_PAIR(4));
mvprintw(LINES - 4, 0, "Entered Moving: Use Arrow Keys to Move and press to end moving");
refresh();
attroff(COLOR_PAIR(4));
move = TRUE;
break;
case KEY_LEFT:
if(size == TRUE)
{ --newx;
++neww;
}
if(move == TRUE)
--newx;
break;
case KEY_RIGHT:
if(size == TRUE)
{ ++newx;
--neww;
}
if(move == TRUE)
++newx;
break;
case KEY_UP:
if(size == TRUE)
{ --newy;
++newh;
}
if(move == TRUE)
--newy;
break;
case KEY_DOWN:
if(size == TRUE)
{ ++newy;
--newh;
}
if(move == TRUE)
++newy;
break;
case 10: /* Enter */
move(LINES - 4, 0);
clrtoeol();
refresh();
if(size == TRUE)
{ old_win = panel_window(stack_top);
temp_win = newwin(newh, neww, newy, newx);
replace_panel(stack_top, temp_win);
win_show(temp_win, top->label, top->label_color);
delwin(old_win);
size = FALSE;
}
if(move == TRUE)
{ move_panel(stack_top, newy, newx);
move = FALSE;
}
break;
}
attron(COLOR_PAIR(4));
mvprintw(LINES - 3, 0, "Use 'm' for moving, 'r' for resizing");
mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)");
attroff(COLOR_PAIR(4));
refresh();
update_panels();
doupdate();
}
endwin();
return 0;
}
/* Put all the windows */
void init_wins(WINDOW **wins, int n)
{ int x, y, i;
```
--------------------------------
### Block Form for Grouping Gems (Ruby)
Source: https://github.com/pmq20/ruby-packer/blob/master/ruby/man/gemfile.5.txt
Groups gems using a block form, with an optional `:optional` flag to control installation. Gems in optional groups are not installed unless specified with the `--with` option during `bundle install`.
```ruby
group :development, :optional => true do
gem "wirble"
gem "faker"
end
```