Difference between revisions of "User:Crutchy"

From SoylentNews
Jump to: navigation, search
Line 2: Line 2:
  
 
PHP/SQL/HTML/CSS and Delphi (Object Pascal) are my preferred languages.<br>
 
PHP/SQL/HTML/CSS and Delphi (Object Pascal) are my preferred languages.<br>
I'm pedantic about code etiquette (indents, spaces, etc).<br>
 
  
New to Perl but interested in learning. I have a basic perl virtual host set up on my dev machine. Also got the slashdev virtual machine going, which makes the prospect of being able to contribute something that might be considered useful to the project a bit more likely.<br>
+
Look out for me on Soylent IRC (#Soylent,##,#test)<br>
 
 
Look out for me on #Soylent IRC.<br>
 
  
 
Crutchy's perl journal: http://soylentnews.org/~crutchy/journal/72
 
Crutchy's perl journal: http://soylentnews.org/~crutchy/journal/72
Line 19: Line 16:
 
[[CssWork|CSS Work]]<br>
 
[[CssWork|CSS Work]]<br>
 
[[IRC]]<br>
 
[[IRC]]<br>
 
==Unit testing==
 
An area that I've been getting into a bit more with some of my other (mainly php) work. It's supposed to be that you write the tests first, but since slashcode is already written it's a bit hard to do that, but some kind of automated regression testing framework probably wouldn't hurt.
 
 
==Code style==
 
Perl programming style guide:<br>
 
http://perldoc.perl.org/perlstyle.html
 
 
Just to start the ball rolling ("borrowed" from perl.org):
 
* closing curly bracket of a multi-line BLOCK should line up with the keyword that started the construct
 
* 4-column indent (slashcode uses tab indents, but in gedit you can set tab width or raplace tabs - tab may be better anyway?)
 
* Opening curly on same line as keyword, if possible, otherwise line up
 
* Space before the opening curly of a multi-line BLOCK
 
* One-line BLOCK may be put on one line, including curlies
 
* No space before the semicolon
 
* Semicolon omitted in "short" one-line BLOCK
 
* Space around most operators
 
* Space around a "complex" subscript (inside brackets)
 
* Blank lines between chunks that do different things
 
* Uncuddled elses
 
* No space between function name and its opening parenthesis
 
* Space after each comma
 
* Long lines broken after an operator (except and and or )
 
* Space after last parenthesis matching on current line
 
* Line up corresponding items vertically
 
* Omit redundant punctuation as long as clarity doesn't suffer
 
If anyone has any others or wants to change any, feel free to do so. Maybe add a reason/background in change summary just so others know where you're coming from.
 
 
We should maybe make a wiki page for coding style and develop it so that all our code is readable and consistent regardless of author.<br>
 
Also looking for one for other languages used for Soylent: CSS, HTML, JS, SQL
 
 
Goes without saying, but HTML and CSS should be W3C compliant.
 
 
==Slashcode==
 
 
Related:
 
 
slashdev journal: http://soylentnews.org/~crutchy/journal/114
 
 
[[Development#Development_VM]]
 
 
IHMO there are way too many folders nested in the slashcode source tree. There may be good reasons but I generally prefer a flat filesystem (as much as possible anyway) for code accessibility. Also helps to reduce likelihood of duplicate filenames. In the slashdev virtual machine I noticed that the apache public directory has links to a lot of the key files in a single directory, which makes things a lot easier.
 
 
What do other devs think of prefixing function names with source filename?<br>
 
For example, main() function in article.pl becomes article__main()<br>
 
Not suggesting that it all be changed to suit this convention right away, but might be handy for new functions to make it easier to figure out where things are declared.
 
 
gedit identifies a syntax error in shtml.pl getFileText function (line 74). Looks like a rogue "s" after the "!-" operator.
 
 
===slashcode files of interest===
 
https://github.com/SoylentNews/slashcode/blob/master/themes/slashcode/htdocs/article.pl
 
 
https://github.com/SoylentNews/slashcode/blob/master/themes/slashcode/htdocs/comments.pl
 
  
 
==Git/GitHub==
 
==Git/GitHub==
 
Related:
 
 
[[GitUse]]
 
 
[[Development#Development_VM]]
 
 
Useful information for beginners:
 
 
https://help.github.com/articles/set-up-git
 
 
https://help.github.com/articles/create-a-repo
 
 
https://help.github.com/articles/fork-a-repo
 
 
https://help.github.com/articles/using-pull-requests
 
  
 
<pre>&#35; apt-get install git</pre>
 
<pre>&#35; apt-get install git</pre>
Line 156: Line 84:
 
$ git push origin master
 
$ git push origin master
 
</pre>
 
</pre>
 +
for master branch can just d:
 +
<pre>git push</pre>
  
 
will output something like the following:
 
will output something like the following:
Line 214: Line 144:
 
I noticed that deployslash.sh script takes a little longer to finish, but does eventually finish.
 
I noticed that deployslash.sh script takes a little longer to finish, but does eventually finish.
 
Tested and seems to work fine for me.
 
Tested and seems to work fine for me.
 
===GIT SHELL SCRIPTS===
 
 
Fetch and merge changes from the upstream remote SoylentNews/slashcode repository:
 
/var/www/slash/git/slashcode-upstream.sh
 
<pre>
 
#!/bin/bash
 
 
cd /var/www/slash/git/slashcode
 
git fetch upstream
 
git merge upstream/master
 
 
exit 0
 
</pre>
 
 
==IRC logging bot==
 
 
had a go at scripting a little quick & dirty irc bot for soylent.
 
 
requires sic (http://tools.suckless.org/sic)
 
 
if you're using debian:
 
<pre>sudo apt-get install sic</pre>
 
 
<pre>
 
#!/bin/bash
 
 
chan="#test"
 
log="test.log"
 
pipe="log-pipe"
 
 
trap "rm -f $pipe" EXIT
 
 
if [[ -f $log ]]; then
 
rm $log
 
fi
 
 
if [[ ! -p $pipe ]]; then
 
mkfifo $pipe
 
fi
 
 
substr="End of /MOTD command"
 
joined=""
 
 
sic -h "irc.sylnt.us" -n "log-bot" <> $pipe | while read line; do
 
if [[ -n "$line" ]]; then
 
echo $line >> $log
 
fi
 
if [[ -z "$joined" ]] && [[ -z "${line##*$substr*}" ]]; then
 
joined="1"
 
echo ":j $chan" > $pipe
 
fi
 
done
 
 
exit 0
 
</pre>
 
 
  
  
 
[[File:crutchy_test.jpg|crutchy's test image]]
 
[[File:crutchy_test.jpg|crutchy's test image]]
 
 
==IRC BOT TESTING==
 

Revision as of 15:03, 17 April 2014

I'm just a regular pleb from Australia. I'm not a member of the Soylent staff.

PHP/SQL/HTML/CSS and Delphi (Object Pascal) are my preferred languages.

Look out for me on Soylent IRC (#Soylent,##,#test)

Crutchy's perl journal: http://soylentnews.org/~crutchy/journal/72

Code doc project: http://soylentnews.org/~crutchy/journal/82

slashdev journal: http://soylentnews.org/~crutchy/journal/114

Watch pages:
Development
Style
CSS Work
IRC

Git/GitHub

# apt-get install git
$ git config --global user.name "crutchy"
$ git config --global user.email ""
$ git config --global credential.helper cache
$ git config --global credential.helper 'cache --timeout=3600'

In my case /var/www/slash is served by apache2 (just on local network). This will be different if you're using the slashdev VM.

$ cd /var/www/slash

$ mkdir git
$ cd git

This creates the directory where I will keep local copies of all my git projects.

FORKING THE "slashcode" REPOSITORY

After logging into GitHub, click the fork button on the Soylent/slashcode repository github page @ https://github.com/SoylentNews/slashcode

$ cd /var/www/slash/git

Download files into a subfolder named slashcode:

$ git clone https://github.com/crutchy-/slashcode.git
$ cd slashcode

When a repository is cloned, it has a default remote called "origin" that points to your fork on GitHub, not the original repository it was forked from. To keep track of the original repository, you need to add another remote named "upstream"

$ git remote add upstream https://github.com/SoylentNews/slashcode.git

Push commits to your remote repository stored on GitHub:

$ git push origin master

PUSHING CHANGES TO crutchy-/slashcode REMOTE REPOSITORY ON GITHUB

Add any files modified to the git commit index:

$ git add "plugins/Ajax/htdocs/images/core.js"
$ git add "themes/slashcode/templates/dispComment;misc;default"

Commit the changes to the local repository index:

git commit

Nano will open with a commented summary of indexed changes.

You must enter a commit message.

^O followed by ^X to save and close nano.

Will get something silimar to following:

[master d573b6d] collapsing/expanding comment tree. changed js function to something more generic.
 2 files changed, 13 insertions(+), 1 deletions(-)
$ git push origin master

for master branch can just d:

git push

will output something like the following:

Counting objects: 21, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (11/11), 1.06 KiB, done.
Total 11 (delta 8), reused 0 (delta 0)
To https://github.com/crutchy-/slashcode.git
   98b4168..d573b6d  master -> master

CREATING A PULL REQUEST

If you want to request the changes that you've made to your fork of slashcode be merged into the upstream repository (SoylentNews/slashcode), you will need to create a pull request.

You do this from https://github.com/crutchy-/slashcode

The pull request button is a little green button to the left of the branch combo. Click it and follow the prompts.

UPSTREAM CHANGES

Fetch any new changes from the original repository:

$ git fetch upstream

Merge any changes fetched into your working files:

$ git merge upstream/master

WORKING OUTSIDE SLASHDEV VIRTUAL MACHINE

The purpose of this was to allow me to share a single local git repository on both the slashdev VM and my host machine.

I'm a perl noob, but I wanted the flexibility of being able to concurrently work on tweaking slashcode to possibly in the apache2/mod_perl2 vhost on my host machine - onfiguration details can be found here: http://soylentnews.org/~crutchy/journal/72

I also want to be able to develop changes that I can test in the VM.


From within VM, to to Devices menu and click "Shared Folder Settings...".

Create a shared machine folder (-readonly,+automount,+permanent) to the /var/www/slash/git/slashcode directory on the host machine.

In a terminal inside the VM:

$ sudo adduser slash vboxsf

Reboot VM.

Again, from a terminal inside the VM:

$ rm /srv/slashdev/slashcode
$ ln -s -T /media/sf_slashcode /srv/slashdev/slashcode

Need to make sure your VM time is set a bit ahead of your host machine time to avoid "Clock skew detected." errors when running deployslash.sh script inside the VM. I noticed that deployslash.sh script takes a little longer to finish, but does eventually finish. Tested and seems to work fine for me.


crutchy's test image