Peer-reviewed code snippets that anyone can edit
follow refactory on twitter
blog
feedback
A wiki for useful code snippets
Bugs? Suggestions?
38-107-191-81
create/login
options
RECENT
STUBS/REQUESTS
STARRED
ACTIVITY
ADD
VIEW
EDIT
FORK
add a new line at end of a text file in every C source
bash
c
cpp
newline
csource
subdirectories
Your work won't be attributed to you
because you aren't logged in.
Login using OpenID or an existing username, or create a username
(no email required) before posting.
Languages
Comma separated. Like
ruby, rails
or
java, swing
Keywords
Comma separated. Like
file, network
Mark as stub
Snippet
Wrap code in
[code=
language
][/code]
- Use
WikiText markup
outside of [code] tags
[code=bash] #!/bin/bash if [ -z "$1" ]; then echo "$0" echo echo "is a command to add a new line at end of a text file" echo "if the last line of the file is not a new line already." echo echo "it is usefull to avoid some C compilers to give warning like" echo "'no newline at end of file'" echo echo sintax: echo $0 "[-v|-q] <file1> <file2> ..." echo echo " -v : verbose mode. write info during processes" echo " -q : quiet mode; no output given (default)" echo exit 1 fi case "$1" in -v ) mode=v shift ;; -q ) mode=q shift ;; *) mode=q ;; esac dirs="$*" for F in $dirs; do LASTLINE=$(tail -n 1 "$F") if [ "$LASTLINE" != "" ]; then echo >> "$F" if [ "$mode" = v ]; then echo "+ : $F" >&2 fi else if [ "$mode" = v ]; then echo "- : $F" >&2 fi fi done [/code]
Log message
Human?
public snippets
This is a community-maintained collection of reusable code snippets.
Contribute something
without logging in, or improve existing contributions. All code is dedicated to the public domain unless otherwise specified.
stats
/
top contributers