Author Archives: Berend de Jong

Minimal AngularJS with http get example

Your script file should have the following contents:

(function() {
  var app = angular.module("SimpleAngularApp", []);

  var MainController = function($scope, $http) {

    var onUserComplete = function(response) {
      $scope.user = response.data;
    };

    var onError = function(reason) {
      $scope.error = "Could not fetch the user";
    }

    $http.get('https://api.github.com/users/berendjdejong')
      .then(onUserComplete, onError);
  };

  app.controller("MainController", ["$scope", "$http", MainController]);

}());

Then for your html file, which should include the script above and the Angular.js script, the contents should be:




  
    
    
    
  

  
    

{{user.login}}

{{error}}

Some important things to note:

  • The html tag contains an attribute with the name of your angular module SimpleAngularApp
  • The anonymous function is called immediately with a so called IIFE to setup the controller
  • The body tag has an attribute ng-controller that references the controller added to the module
Share

Immediately invoked function expression IIFE

Below is a code snippet for a Immediately invoked function expression IIFE. An IIFE is used to keep code out of the global namespace.

(function() {
  var createWorker = function() {
    
    var workerCount = 0;

    var task = function() {
      workerCount += 1;
      console.log("task " + workerCount);
    };

    return {
      task: task
    };
  };
  
  var prg = createWorker();
  
  prg.task();
  
}());
Share

Windows GIT and SSH keys

gitTo use SSH keys on your windows system follow the steps below:
Install the git extensions for windows. This will (among other things) install the Git Bash shell. Execute a git bash shell. Now create your private/public key pair with the ssh-keygen command (or copy an existing key). Add a passphrase for additonal security.

On windows the ssh files are store in c:\Users\Administrator\.ssh\

Copy the public part to your git server with the ssh-copy-id command.

In Git bash edit your .profile (or create one) and add the coding snippet below:

SSH_ENV=$HOME/.ssh/environment

function start_agent
{
   echo "Initialising new SSH agent..."
   /usr/bin/ssh-agent | sed 's/^echo/#echo/' > ${SSH_ENV}
   echo succeeded
   chmod 600 ${SSH_ENV}
   . ${SSH_ENV} > /dev/null
   /usr/bin/ssh-add;
}

if [ -f "${SSH_ENV}" ]; then
   . ${SSH_ENV} > /dev/null
   ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
      start_agent;
   }
else
   start_agent;
fi

If you have multiple keys you should also create a config file in the .ssh folder. In this file you specifiy which key should be used for what host; like this:

Host yourhost.nl
 IdentityFile ~/.ssh/your_key_for_this_host
Share

Create eventlog on commandline

With the command below you can easily create a new windows eventlog. The command creates an informational event in the specified source; automatically creating the source if it does not exist.

EventCreate /L Application /T Information /ID 900 /SO "Your.Eventlog" /D "With a description"

EventLogCreate
/L The eventlog to create an event inEvent
/T Information
/ID The event ID for the event
/SO The source for the event
/D is description

Share

Configure FileZilla and ProFTPD with TLS

Filezilla-logoThis post shows you how to connect to a ProFTPD server which requires a TLS connection. TLS is an extra layer of security over the standard FTP protocol used by ProFTPD.

First of all install a copy of…..FileZilla and start it up. Next go to the Site Manager (File -> Site Manager… or type Ctrl+S).

Press the New Site button and give your site a logical name; proftpd.example.com for example. Next fill out the dialog as shown below; adjust values where appropriate (host and portname for example).
Screenshot from 2014-11-11 16:35:15
Next go to the tab Transfer Settings and choose for the Transfer mode the value Active . See also the picture below.
FileZilla Site Manager

Allright that’s all for your FileZilla configuration. Press the Connect  button to make a connection with this ProFTPD instance. If you have never visitied this FTP server before in this FileZilla session a window will, probably (not if the FTP server uses a known certificate), popup which says Unknown certificate . See the dialog below.
FileZilla - Unknown Certificate

Check the Subject  and the Issuer  of the certificate; are they familiar? Yes, continue choose no otherwise. Check also the session details. The host should be the same as the one you are trying to connect to. If everything is fine you could choose to always trust this site but that is up to you.

HTH

Share

Virtualbox USB support: missing USB devices

Virtualbox_logoIn case VirtualBox does not recognize your USB devices on a *nix system you can solve this by adding your username to the vboxusers  group. Do this by executing the command:

# replace username with your, gues what, username
sudo usermod -G vboxusers -a username

Logoff and logon, start virtualbox and you should be able to access your USB devices. To access an USB device on a guest be sure to add it to the “USB Device Filters” (right click guest; choose Settings -> USB tab).

Also be sure to install the right extension pack for your virtualbox installation.

Share

Setup GIT server

This post describes how to setup your ubuntu server as a GIT server. Clients are able to clone repositories and push their changes back to the server with this setup. We make use of ssh in combination with the git-shell to provide extra security.git

On your GIT server execute the commands below:

sudo apt-get install git
sudo adduser git
vi /etc/shells # add "/usr/bin/git-shell"
vi /etc/passwd # change shell for user git to "/usr/bin/git-shell"
touch /home/git/.hushlogin # prevent welcome message on ubuntu system
mkdir /home/git/git-shell-commands
vi /home/git/git-shell-commands/no-interactive-login # add text below
#!/bin/sh
printf "\nInteractive shell access not provided; go away!\n\n"
exit 128
#end add text
chown -R git:git /home/git/git-shell-commands
chmod u+x no-interactive-login

If you use a Synology server add the following line to your /etc/shell file:
/var/packages/Git/target/bin/git-shell

Create a bare GIT repository on the server at /opt/git:

mkdir /opt/git
mkdir /opt/git/the_project.git
cd /opt/git/the_project.git
git --bare init
chown -R git:git /opt/git

Now on your local machine create a repository  and push it to the server:

cd ~/
mkdir the_project
git init
git add .
git commit -m "Initial commit"
git remote add origin git@yourgitserver:/opt/git/the_project.git
git push origin master

To clone the repository to your local development machine execute the following commands:

git clone git@yourgitserver:/opt/git/the_project.git
# this will clone the repository into a directory "the_project".
git status # check the status of the repository
git log # check the log messages
git tag # list the tags available
git checkout v1.0.0 # check out the v1.0.0 tag
# With the "git status" command you can see that the HEAD is detached:
# HEAD detached at v1.0.0
git checkout master # back to HEAD version
# No longer a detached head message when you execute "git status":
# On branch master

When you have made changes to a file you want to undo (revert changes back to the last commit) execute the command below:

git checkout -- yourfile.txt

GIT and SSH public / private key

If you want to use git with a SSH key follow these steps. A SSH key is a convenient (and very secure!) way to login to your server. First create a public / private key pair with the command (-t is the type of encryption and -C is a comment):

ssh-keygen -t rsa -C "git @ repo machine"

Protect this key with a strong passphrase. After the key is generated you have to copy the public part to the server. Off course this should also be done in a secure way so use the ssh-copy-id tool for this. Execute the command:

ssh-copy-id -i gitkey git@yourmachinehis will copy the private key to the user home directory in a folder .ssh with the name authorized_keys.
 Now ssh to your machine with the command:
ssh git@yourmachine

The ssh_agent will ask for your passphrase (not the user password) and remember it. If you don’t have a ssh_agent enabled you could do without the passphrase but that is a bit less secure.

Share