Cocos
cocos (code commons) - auto-include quick-starter prelude & prolog
Install / Use
/learn @rubycocos/CocosREADME
cocos (code commons) - auto-include quick-starter prelude & prolog
- home :: github.com/rubycocos/cocos
- bugs :: github.com/rubycocos/cocos/issues
- gem :: rubygems.org/gems/cocos
- rdoc :: rubydoc.info/gems/cocos
Intro - Why?
Reason No. 1
After starting of too many scripts (hundreds?) with adding more and always repeating the same dozen modules with require e.g.:
require 'pp'
require 'time'
require 'date'
require 'json'
require 'yaml'
require 'base64'
require 'fileutils'
require 'uri'
require 'net/http'
require 'net/https'
...
why not use a more "inclusive" prelude & prolog and replace the above with a one-liner:
require 'cocos' # auto-include code commons quick-starter prelude & prolog
Reason No. 2
After reading too many text files in utf-8 and always repeating the same open / read and code block dance e.g.:
txt = File.read( "history.txt" )
# sorry - will NOT guarantee unicode utf8-encoding
# (e.g. on microsoft windows it is ISO Code Page (CP-1252
# or something - depending on your locale/culture/language)
txt = File.open( "history.txt", "r:utf-8" ) do |f|
f.read
end
Or after reading and parsing too many json files (by default always required utf-8 encoding) and always repeating the same open / read and code block dance again and again e.g.:
txt = File.open( "history.json", "r:utf-8" ) do |f|
f.read
end
data = JSON.parse( txt )
Why not use read convenience / short-cut helpers such as:
txt = read_txt( "history.txt" )
data = read_json( "history.json" )
And so on.
Usage
Read / Parse
Read / parse convenience short-cut helpers
read_blob( path )
read_text( path ) <br>
also known as read_txt
read_lines( path )
read_json( path ) / parse_json( str )
read_yaml( path ) / parse_yaml( str ) <br>
also known as read_yml / parse_yml
read_csv( path ) / parse_csv( str )
note: comma-separated values (.csv) reading & parsing service brought to you by the csvreader library / gem »
read_data( path ) / parse_data( str )
note: alternate csv reader / parser; reads data WITHOUT headers, that is, named columns - returns data array not named hash (table)
read_tab( path ) / parse_tab( str )
note: tabulator (\t)-separated values (.tab) reading & parsing service
brought to you by the tabreader library / gem »
read_ini( path ) / parse_ini( str ) <br>
also known as read_conf / parse_conf
note: ini / conf(ig) reading & parsing service brought to you by the iniparser library / gem »
That's it for now.
License
The cocos scripts are dedicated to the public domain.
Use it as you please with no restrictions whatsoever.
Related Skills
node-connect
345.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
104.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
