Skip to content

Instantly share code, notes, and snippets.

View alganet's full-sized avatar

Alexandre Gomes Gaigalas alganet

  • São Paulo, SP, Brazil
View GitHub Profile
@alganet
alganet / answer.sh
Last active January 29, 2022 03:49
Capturing keyboard events on any shell
#!/usr/bin/env sh
# This script captures keyboard events on popular POSIX Shells.
#
# Run it by executing ./answer.sh and press the arrow keys
# to see the capture exemple. Press Return to exit.
#
# It has been tested on:
# - Windows (Git Bash and MSYS+Mintty)
# - OS X (native terminal, Yosemite)
@alganet
alganet / arch.md
Last active August 29, 2015 14:20
@alganet
alganet / md.md
Last active March 19, 2018 11:55
Non-Fluent Respect\Validation

Non-Fluent Respect\Validation

Hi! I'm one of the developers of Respect\Validation and other less known Respect components. Feel free to ask any questions here or on reddit.

There are many micro-frameworks that rely on magic methods. We don't. In this article I'm gonna explore the Respect\Validation API without fluent interfaces or magic methods. I'll use a traditional dependency injection approach.

The following validator was inspired by one of our README examples:

@alganet
alganet / serve.sh
Last active July 17, 2020 05:42
Serve any folder as a web server with $ curl -L http://tinyurl.com/servesh1 | sh
#!/usr/bin/env sh
# serve.sh
# Modular version: https://gist.github.com/alganet/a22a1373dcee7c175d1e
# Expansion on zsh
command -v setopt 2>&1 >/dev/null && setopt SH_WORD_SPLIT
# POSIX on bash
export POSIXLY_CORRECT=1
# Lists files and folders as HTML
@alganet
alganet / answer.sh
Created September 21, 2014 13:03
testing
answer_cr=$(printf '\r')
answer_esc=$(printf '\33')
answer_oldterm=''
answer_focused=-1
answer_total=0
answer_widgets ()
{
answer="$1"
echo "$answer" |
@alganet
alganet / 00-index.sh
Last active September 28, 2019 21:25
POSIX Shell HTTP/CGI application. Run as ./00-index.sh in ksh, dash, bash or zsh
# Main file, loads dependencies and holds application code
# Usage:
# $ git clone https://gist.github.com/a22a1373dcee7c175d1e.git
# $ cd a22a1373dcee7c175d1e
# $ chmod +x 00-index.sh
# $ ./00-index.sh
#
# Use sudo if your machine denies an address to netcat
#
@alganet
alganet / exists.cmd
Last active November 19, 2018 14:21
sh/bat hybrid that checks available commands. Despite its hackish look, it was tested under Windows XP, wine, ksh, zsh, dash and bash.
: ::\
@echo off
rem () ( command -v $1 >/dev/null 2>&1; return $? )
rem : "Usage sh: $ sh exists.cmd ls && echo exists "
rem : "Usage bat: > exists.cmd notepad "
rem : " > echo %ErrorLevel% "
rem $1 <<REM
:exists
@alganet
alganet / hybrid.cmd
Last active August 29, 2015 13:57
Hybrid sh/bat script and data file
rem () ( $* ) # Mosai Script Hybrid 1.0
rem : "Usage: sh hybrid.cmd (shell), hybrid.cmd (win/wine), cscript /nologo /E:vbscript hybrid.cmd"
rem echo "HELLO FROM SH!!!"
rem <<REM
'&&@echo off && cls && goto :WScript.Quit
WScript.Echo "HELLO FROM VBS!!!"
:WScript.Quit
'& echo HELLO FROM BATCH!!!
'& exit /b
rem raw scripts to be used here
@alganet
alganet / scrito
Last active August 29, 2015 13:57
Prototype for Mosai Script Tools 1.0. Works on sh, bash, ksh, zsh, and cmd on Windows and Wine! No dependencies.
#!/usr/bin/env sh
scrito () ( : )
# Static version information
scrito_v () ( scrito_version )
scrito_version () ( echo "Mosai Script Tools 1.0" 1>&2 )
# Short help text
scrito_h () ( scrito_help )
<?php
namespace Escher;
use ReflectionFunction;
class Test
{
protected $behavior;
protected $status = true;