Skip to content

Instantly share code, notes, and snippets.

@lnznt
lnznt / string-ex.rb
Last active October 3, 2015 19:48
String#remove / String#- (Ruby)
#!/usr/bin/env ruby
module StringEx
def remove(re)
gsub(re) {}
end
def wrap(w)
"#{w[0]}#{self}#{w[-1]}"
end
@lnznt
lnznt / ezput.h
Created April 28, 2012 06:11
macro: put_d() (C language)
#ifndef INCLUDED_EZPUT_H
#define INCLUDED_EZPUT_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <stdio.h> /* printf() */
#include <ctype.h> /* isprint() */
@lnznt
lnznt / special_name_method_definition.rb
Created April 28, 2012 06:46
The method definition of a special name. (Ruby 1.9)
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
# The method definition of a special name. (Ruby1.9)
#
class C
def a?(x) ; :foo ; end
def a!(x) ; :foo ; end
def a=(x) ; :foo ; end
@lnznt
lnznt / Makefile
Created April 29, 2012 04:22
sample: 'hello world' parser (Ruby/Racc)
#!/usr/bin/make -f
# -*- coding: UTF-8 -*-
#
# to generate 'foo.rb' from 'foo.ry'
#
# ex.1) $ make foo.rb
#
# ex.2) $ make FLAGS=-C foo.rb # syntax check only
#
@lnznt
lnznt / llist.h
Created May 1, 2012 01:53
[sample] linked list (C language)
/*
llist.h
*/
#ifndef INCLUDED_LLIST_H
#define INCLUDED_LLIST_H
#define llist_init(l_) ((l_)->next = (l_)->prev = (l_))
#define llist_next(l_) ((l_)->next)
#define llist_prev(l_) ((l_)->prev)
@lnznt
lnznt / percent.rb
Created May 1, 2012 02:55
[sample] the % notation [ %!...! ] (Ruby)
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
# $ ruby -v
# ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
#
p %!abc!
p %"abc"
@lnznt
lnznt / percent_Q.rb
Created May 1, 2012 03:12
[sample] the % notation [ %Q!...! ] (Ruby)
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
# $ ruby -v
# ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
#
p %Q!abc!
p %Q"abc"
@lnznt
lnznt / percelt_q.rb
Created May 1, 2012 03:43
[sample] the % notation [ %q!...! ] (Ruby)
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
# $ ruby -v
# ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
#
x = "xyz"
@lnznt
lnznt / percent_s.rb
Created May 1, 2012 03:56
[sample] the % notation [ %s!...! ] (Ruby)
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
# $ ruby -v
# ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
#
x = "xyz"
@lnznt
lnznt / percent_w.rb
Created May 1, 2012 04:40
[sample] the % notation [ %w!...! ] (Ruby)
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
# $ ruby -v
# ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
#
x = "xyz"