Mar 10, 2014

How to add a new snippet for Zed?

Following this introduction to Zed, I encountered a problem to create a snippet. It's actually an open issue.
So I wanted to share it here.

I also wanted to share a few things I added to my user.json file. It's also a good idea to back it up as you could use it in any chrome browser you could find.
    "preferences": {
        "theme": "monokai",
        "scrollSpeed": 4,
        "gotoExclude": ["/tags", "*.png", "*.gif", "*.jpg", "*.mp4"]
    }
In the exclude part,  I added a few extensions that I encounter while working on web projects. It saves some time when you look for a file with the Ctrl-E command.
I also added the ctp extension (from CakePHP) to be managed with the PHP mode.

Here is an example if you want to use Zed snippets system with PHP :
    "modes": {      
        "php": {
            "name": "PHP",
            "highlighter": "ace/mode/php",
            "extensions": ["php", "php4", "ctp"],
            "commands": {
                "Tools:Complete:Snippet": {
                    "scriptUrl": "/default/command/snippet_completer.js",
                    "snippets": {
                        "class": "class=\"${1}\"",
                        "foreach": "foreach (${1} as ${2}) {\n\t${3}\n}",
                        "if": "if (${1}) {\n\t${2}\n}",
                        "php": "<?php ${1} ?>"
                    }
                }
            },
            "handlers": {
                "complete": ["Tools:Complete:Builtin","Tools:Complete:Snippet"]
            }
        }
    }
If you want to add your own, just duplicate the lines under snippets.

Feb 18, 2014

Deploy to your FTP through BitBucket ... and soon Github

Update - August 2016
FTPbucket is a PHP script that enables you to sync your BitBucket or GitHub repository with any web-server. It works with Git and Mercurial.

This post is outdated. Please go directly to Github to find the latest informations.

FTPbucket is a PHP script that enables you to sync your BitBucket repository with any FTP account.

I was looking for an easy solution to use Git on a webproject with a server with no Git installed (hehe). After checking several solutions, I could not find a free one that could fits my needs.

So :

Installation

  • Get the code here
  • Edit the config file and rename it to 'config.php'
  • Copy the deploy folder on your FTP server
  • On Bitbucket>Admin>Hooks, setup a POST hook pointing to http://myserver/deploy/deploy.php
  • You can Push now!

Limitations

  1. The script only copies the files you are pushing. It means that if you start with this tool when you already have files in your BitBucket repo, they won't be copied on the server. I'm looking for solutions on a full deploy. Which brings me the second point.
  2. I tried to push a 160Mo repo with more than 26 000 files and the POST hook didn't like it. The limit is ~1000 files/push I think. It's an unsolved issue: https://bitbucket.org/site/master/issue/7439/git-post-commit-hook-payloads-has-empty
SOLUTION : When you create a new repo on BB and need to push a lot of files, just do it. Right after, you set up the POST hook and manually copy the repo and FTPbucket files on your FTP.

More

It should work with Mercurial too but it's not tested yet.

I'm sure a lot of improvements can be made to my code so don't hesitate to fork and improve it! I would be glad to hear about your tests and issues too.

ToDo

I would like to have a simple GUI to manage logs and configs
I need to implement a way to call for action, when the file copy is done. A post-commit hook.
Add support for SSH, Github and more ...

Feb 12, 2014

If you want to get more serious/playfull, get Zed!


Zed is a code editor based on ACE.
The idea is to get a really strong IDE but with a minimalistic UI. And I really like that. I often work with PHPDesigner as I like the holding-your-hand way of doing things.
But sometimes, it's really too much. And it feels like there is an awful lot of wasted space in that kind of tools. The success of code editors based on ACE or with similar looks (Sublime Text) shows the need for such simplicity.


An open project with the 'Project Picker' in the front

I forgot the other good news, you don't need to install anything because it's a Chrome extension: Give it a try

The 'Cheatsheet' will display on many occasions and it's a good kick-starter. Or you can click on 'Manual' to get to it.

Example

As it can be a little bit disturbing at first, I will show you how to change the theme (syntax highlights).

  • Click on 'Configuration'
  • Press 'Ctrl-E' to open a file from this project
  • Type 'user.json' then press 'Enter'. The skeleton is there but it's empty
  • Now 'Ctrl-2' to split the screen in 2 (I like the Ctrl-1-2-3 commands to split the screen as it reminds me of RTS games when you make your teams)
  • On the new window, open 'preferences.json'
As the latest is Read-Only, you need to copy the things you want to change in the 'user.json' window. Like this :
To find the one that suits you, you can try them here.

Conclusion

On the GitHub repo, you can find a lot of files explaining ALL you need to know about Zed but it really needs a Wiki to centralize all that!

Anyway, it's really fun to code with it. It can be challenging to a beginner but it's also a cool way to learn.

Next step: I will try to work on a Dropbox folder and set up an automatic sync with a FTP account.

Jan 24, 2014

Setting up a git server like a Paas


I have this new server that I wanted to use like the services offered by Paas's. After some disappointments with OpenShift and Appfog, I am now using Heroku. And I really love like it! On Heroku, you just Push with Git and your site is up-to-date.

So, until I had to install my own Git server, I never made the difference between the bare repository and the working tree.

Just to make things clear, the bare repo does not contain files, it's just the information about who did what on which file. It's the center/server of your git network. More details here
All the files you have on your repo are a working tree. You can't push to a working tree.

But if you can easily find free server services (Assembla, Bitbucket), it's not a deploy option like in Heroku.
If you are working on a web project, you would like to check the result "live" without having to update it manually.

This is what I did :
1. I installed git on the server
(yum or apt-get or ...) install git-core
2. I created a git user
adduser git 
It will set the new user with no password or '!!'. It may cause problems, so to be sure you can unlock the user
passwd -u git
3. I had to register my SSH key (switching to 'git' user is really important)
su - git
cd
mkdir .ssh
ssh-keygen -q -t rsa -N 'pass' -f ~/.ssh/id_rsa
ssh-add
# on CentOS you may need to 'exec ssh-agent bash' to avoid the 'Could not open a connection to your authentication agent.'

cat .ssh/id_rsa.pub >> .ssh/authorized_keys 
4. I did the work tree in a web-browser-accessible folder (public_html, www ...) and put a test file to avoid any bug related to cloning an empty repo
git init deploy
cd deploy
touch test
git add .
git commit -m 'first'
5. Now the bare repo. You should put in your /home/git folder
git clone --bare /home/user/www/deploy deploy.git
6. To clone it on my PC, I append my own SSH public key to .ssh/authorized_keys ...
#On the server
cat /tmp/id_rsa.pub >> .ssh/authorized_keys
You can also copy the content of your id_rsa.pub and paste with
nano authorized_keys
7. ... and cloned the repo on my machine
git clone git@myserver:/home/git/test.git
If you change your code and Push it, it will work but you won't change the deploy folder

8. I had a hook to the bare repo to tell update the live version
cd /home/git/deploy.git/hooks
touch post-receive
nano post-receive
Paste
#!/bin/sh
GIT_WORK_TREE=/home/user/public_html/deploy/ git checkout -f
 Save and exit, then make it executable
chmod +x post-receive
9. Done! You can push and it will appear on the web folder

Jul 22, 2013

OpenFL : Embedding a MovieClip with timeline


With the latest versions of OpenFL, the Assets Class works great but if you use it for a swf containing a MovieClip with a timeline, you can't use your mc properly (currentFrame, totalFrames ... does not work).

Has it took me a lot of time to figure it out, I'm copying here a solution that I found from the creator himself : http://www.openfl.org/forums/general-discussion/openfl-problems-swf/

The trick is to put
<haxeflag name="-swf-lib" value="path/to/your.swf" if="flash" />
in your build file.
Then, you can use it like this :
import MovieClipName;
 [...] 
var mc = new MovieClipName(); 

With HaXe and FlashDevelop, it's somehow easier as you can right-click on your lib and select "Add to library ..." and it will change the build command for you.

Jul 15, 2013

Using FlashDevelop with Openfl

Just to make things clear, OpenFL is the sequel of NME. NME is working great with HaXe 2 and latest versions of FD but if you want to make FD, HaXe and OpenFL working hand in hand this is the trick :

  1. Install HaXe and Neko http://haxe.org/download
  2. Install the latest beta version of FlashDevelop http://www.flashdevelop.org/community/viewtopic.php?f=9&t=3529 It's 4.4.3 right now.
  3. You need to tell FD where the hell is HaXe. Go in Tools>Program Settings. Under HaxeContext, you have Installed SDKs. Click on the 3 dots
  4. Click Add and on the Path field, add the path to your HaXe install folder (might be something like C:\HaxeToolkit\haxe)
  5. Now you can build HaXe projects. To install OpenFL, I'm using haxelib. So open the Command Prompt. You can even do it from FD!
  6. Make sure you have a lib folder in your HaXe folder and type haxelib install openfl. Then haxelib run openfl setup. It might needs other libraries: haxelib install actuate, haxe install swf.
  7. Now you can go to Project>New Project... Under the HaXe section, you pick OpenFL project
  8. Press F5 to test and BOOM, it WORKS! (I sincerely wish it)

Dec 4, 2012

Motto

“The winning army realises the conditions for victory first, then fight. The losing army fights first then seeks victory.” 
— Sun Tzu