Skip to content

Instantly share code, notes, and snippets.

View ammar's full-sized avatar

Ammar Ali ammar

  • Ramallah, Palestine
View GitHub Profile
@ammar
ammar / tmate-session
Created August 17, 2017 15:13
Tmux script to setup a tmate session (a rails app directory tree in this case)
#!/bin/bash
tmux_session=pair
tmux rename-session 'pair'
tmux rename-window 'shell'
tmux send-keys -t $session_name:1 'source .env' Enter
tmux new-window -t $tmux_session:2 -n 'root'
#!/bin/bash
key=`cat ~/.ssh/id_rsa.pub`
for host in $*; do
ssh $host "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod 700 ~/.ssh && chmod -R 600 ~/.ssh/* && echo '$key' >> ~/.ssh/authorized_keys"
done
@ammar
ammar / absent_operator.patch
Created July 10, 2017 12:32
WIP: Add support for new absence operator
diff --git a/lib/regexp_parser/scanner/scanner.rl b/lib/regexp_parser/scanner/scanner.rl
index e200cfc..96b2e70 100644
--- a/lib/regexp_parser/scanner/scanner.rl
+++ b/lib/regexp_parser/scanner/scanner.rl
@@ -78,6 +78,8 @@
conditional = '(?(';
+ absent_operator = '?~';
+
diff --git a/test/expression/test_base.rb b/test/expression/test_base.rb
index 21d22d0..27b253f 100644
--- a/test/expression/test_base.rb
+++ b/test/expression/test_base.rb
@@ -65,7 +65,7 @@ class ExpressionBase < Test::Unit::TestCase
assert_equal '@0+12', root.coded_offset
# All top level offsets
- checks = [
+ [
@ammar
ammar / mrun
Last active January 3, 2016 23:49
Run commands and tests on multiple ruby versions. (ruby-build/chruby version)
#!/bin/bash
# A bash function/script used to run commands and tests using all the
# ruby-build-installed and chruby-managed versions of ruby on the system.
# Usage: mrun [command | script name]
#
# Without arguments, mrun will look for an executable file named run and run
# it. If an executable named run is not found, it will run rake. When given
# an argument (a script or a command, like bundle), it will run it with every
@ammar
ammar / ruby_wrappers.c
Created May 25, 2012 10:23
Examples of wrapping rb_funcall and rb_funcall2 with rb_rescue2.
#define MY_FUNCALL_ARGC 3
VALUE my_funcall(VALUE receiver, ID method_id, int argc, ...);
VALUE my_funcall_ex(VALUE data);
VALUE my_funcall2(VALUE receiver, ID method_id, int argc, VALUE *argv);
VALUE my_funcall2_ex(VALUE data);
// my_rescue: exception handler used by both of the wrappers below.
@ammar
ammar / multispec.sh
Created November 11, 2010 06:08
A quick and dirty solution to run my specs through multiple ruby versions.
# Poor man's multiruby, a wrapper bash function/script around rvm. This is
# used to run all the specs through all the supported versions of ruby.
#
# Requires that all the rubies listed below are installed via rvm, and rvm to
# be sourced in the environment.
#
# rvm install ${version};
#
# To install the required gems, run the following:
#
@ammar
ammar / ctype.rb
Created November 10, 2010 22:24
Another take on Ctype
# defines character type constants (as arrays) and methods that test
# whether a given character belongs in one of them.
module CType
Digit = ('0'..'9').to_a.freeze
Lower = ('a'..'z').to_a.freeze
Upper = ('A'..'Z').to_a.freeze
Alpha = [Lower, Upper].flatten.freeze
Alnum = [Alpha, Digit].flatten.freeze
Word = [Alnum, '_'].flatten.freeze
@ammar
ammar / chop_utf8.rb
Created November 3, 2010 15:55
UTF-8 aware string chop. (the firs gist was posted as anonymous)
# The rubyist version. Thanks to James Edward Gray II
def chop_utf8(s)
return unless s
lead = s.sub(/.\z/mu, '')
last = s[/.\z/mu] || ''
[lead, last]
end
@ammar
ammar / ctype.rb
Created October 28, 2010 09:08
Character type identification module
module CType
def self.alnum?(c); c =~ /[[:alnum:]]/ ? true : false end
def self.alpha?(c); c =~ /[[:alpha:]]/ ? true : false end
def self.blank?(c); c =~ /[[:blank:]]/ ? true : false end
def self.cntrl?(c); c =~ /[[:cntrl:]]/ ? true : false end
def self.digit?(c); c =~ /[[:digit:]]/ ? true : false end
def self.graph?(c); c =~ /[[:graph:]]/ ? true : false end
def self.lower?(c); c =~ /[[:lower:]]/ ? true : false end
def self.print?(c); c =~ /[[:print:]]/ ? true : false end
def self.punct?(c); c =~ /[[:punct:]]/ ? true : false end