четверг, 24 июля 2014 г.

Cell phone and desktop games

There are multiple initiatives in making cell phone as a heart of digital world. Indeed, it is small, and almost always together with the owner. You can use it to control your PC, play games, or turn on your coffee machine.

Let's see some of todays applications of cellphone and computer communication.

Roccat Power Grid

Roccat allows us to pair our cell phone and computer at first place. You can start applications, and control state and health of you PC. Load second-screen games.


Roccat builds applicaitions themselves, and they hier :) Simple gamer has access for setting custom macroses for gaming. What is interesting at this place, is if i am able to come anywhere (computer club, or my friends home) and have access to those so-called "profiles" ? Armaggeddon gaming mice allow this kind of feature. For sure - you can share your profiles, but this is another approach.

Roccat puts this software as opposed to devices (like Armaggeddon or Mad Catz R.A.T. and of course S.T.R.I.K.E. 7, maybe others...).

From tutorials on their website we can learn that we can create our own grids with predefined functionality. You can open websites, launch applications, and read RSS feeds, mails and skype messages. Last functionaly looks weird, because you have all this features on your cell phone itself.

Biggest customization looks to be a macro creation. This allows you to record keyboard sequencies and then repeat them in games. Same customization can be found in... mice :) this looks weird but true. Armaggeddon AlienCraft-II G13 and Mad Catz R.A.T. 9 have these functions.

Brass Monkey

This effort is primiary built for online game developers. When you work on your game - you can use brass monkey system to allow gamers to play with their cell phones. It supports HTML5, Unity3D and flash.

Among interesting facts - their HTML5 uses flash to communicate with cell phone. To initiate connection they propose clients to use external discovery mechanizm, which collects local IPs and public IPs of users to match those. Basically, you just have to turn on your phone and a game - and you are ready to play!

For customizations you get ability to change so-called layouts on cell phone and create buttons. Both are based on images, which are pushed from your game to the device to display. There are also serveral predefined control modes. Also, you can get access to accelerometer.

In addition, if you start working with brass monkey - you get opportunity to use their games monitization. You can get payed for goods, game time, or entire game purchase.


Adobe Wand

This is latest effort from Adobe. You get cell phone application together with Air Runtime for Android or iOS. Connection with wand-enabled game is done using PIN, which allows flash game to find your cell phone.

For customization purposes, you can set background image of cell-phone and get access to touch events, and accelerometer of mobile device. Game can also request mobile device to vibrate.

Wand is very new, it comes with 14th version of flash related software.

воскресенье, 26 января 2014 г.

Asus Z99Le surgery

Today decided to look inside my old laptop. I wanted to remove all useless parts and see what can I upgrade there. Unfortunately, as I understand I can use only 2Gb RAM, and cannot upgrade to 4Gb. But I think i can put SSD inside it. There is SATA2 (SATA 3Gb/s, as it is written on my HDD), I can plug it there, or I can use micro PCI Express port. I wonder if BIOS will be able to use them. Also quite interesting if I can upgrade CPU?..
Lets see what's inside.

Top side

 
1 - DVD/ROM. Removed. It was broken anyway,
2 - video connection ports,
3 - WiFi wires :) these go from WiFi card (5) to screen. It looks like screen is an antenna also,
4 - battery,
5 - micro PCI Express WiFi card. It is connected to monitor. I think it can be replaced with SSD,
6 - 160Gb HDD. It says SATA 3Gb/s. As I understand this is SATA2, and again, this is another place where I can try to plug SSD disk.

Bottom side


1 - DVD ROM again,
2 - 2xDDR2 1Gb RAM. As i mentioned, maximum size of RAM which I can install is 2Gb, even there are RAM cells 2Gb each, and there are 2 ports,
3 - processor. I believe it is possible to replace it, I wonder if it is possible to upgrade it somehow,
4 - cooling system. It's much bigger then processor itself,
5 - battery,
6 - plugged 160Gb HDD, SATA2 (?),
7 - plugged mini PCI Express WiFi card.

Screws :)


суббота, 30 ноября 2013 г.

Flymake for JS Hint tool

Abstract

First, I tried to implement own jshint invocation and handling tool. It was pretty fun, but later I found flymake package designed to work with syntax checking tools.
This article is based, and describes JS-Hint mode. It can be treated as development log and tips, as well as short tutorial on how to customize flymake mode.

Flymake

Flymake allows us to define interface to check files, tools to run these checks from time to time, and regexp based tools to highlight broken parts of the files.

Invoke

The entry point of flymake is how to invoke check program:
01 (defun flymake-js-hint-init ()
02   (let* ((temp-file (flymake-init-create-temp-buffer-copy
03                      'flymake-create-temp-inplace))
04          (local-file (file-relative-name
05                       temp-file
06                       (file-name-directory buffer-file-name))))
07     (list "jshint" (list "--verbose" local-file))))
This code, as well as most of the other code is taken from  Example—Configuring a tool called via make.
This function makes a copy of current buffer state into temporary file with unique name, and returns line to be called by flymake. The output usually contains errors and warnings, which is parsed and corresponding lines are highlighted.

Highlight

Flymake uses special list to hold all possible highlights -  flymake-err-line-patterns. Each entry in this list is a list of next format:
(REGEXP FILE-ID [LINE-ID [COLUMN-ID [ERROR-TEXT-ID]]])
where:
REGEXP - what kind of lines to match, with groups,
FILE-ID - id of group in match containing file name with error/warning,
LINE-ID - id of group in match containing line in the file with error/warning,
COLUMN-ID - id of group in match containing column in line
ERROR-TEXT-ID - id of group in match containing message to display against corresponding line.
Example for jshint:
01 (add-to-list 'flymake-err-line-patterns
02              '("^\\(.+\\): line \\([0-9]+\\), col \\([0-9]+\\), \\(.+\\)$" 1 2 3 4))
This code adds new rule to flymake list of rules. Next time flymake find line with error corresponding to this regexp - it will highlight it.

Register for flymake

When we have required parts of running and highlighting, we can link this all together and configure flymake:
01 (add-to-list 'flymake-allowed-file-name-masks
02              '(".+\\.js$"
03               flymake-js-hint-init 

04               flymake-simple-cleanup 
05               flymake-get-real-file-name))
flymake-allowed-file-name-masks - is a list of rules for flymake. Each entry is of the form:
(REGEXP INIT-FUNCTION CLEANUP-FUNCTION GETFNAME-FUNCTION)
where:
REGEXP - is used to match a file,
INIT-FUNCTION - initializes a temporary file with current buffer context and returns specialized function as list,
CLEANUP-FUNCITON - removes temporary file and does other clean up functions,
GETFNAME-FUNCTION - maps temporary file names to real ones.

Links

[1] Flymake mode

вторник, 26 ноября 2013 г.

Emacs Keymaps and Packaging

Abstract


We currently have nice piece of code, able to remove trailing spaces for .java files. We might add some other functionality into that code. For example, I have pieces of code which add spaces after if statements just before opened brace when I save .js file, and removes them when I open one. This makes my comrade developers feel like code is so-called "readable", and I can keep programming in my favourite manner.
To be able to spread code amongst multiple computers and environments, we will have to either copy files all the time, or use Emacs packaging system. This will also provide us an ability to share our library. So your friends will be able to use your packages in their own environments and be up to date with them.
Also, we will look at keymaps - short cuts for interactive functions. These are widely used, and in case you want to make your environment look like Intellij Idea, you can use them. Personally, I think that less used functions should persist in M-x calls family. This does not pollute your short cuts, which are pretty tight, and long short cuts look not so sexy as expected. Another reason is that, maybe, long command looks much more understandable and easy to search.

Keymap

Lets start by linking our function to some short cut. Emacs allows setting short cuts on global, local and per-mode keymap level.
Local keymap is something user might define for particular buffer.
Global keymap can be changed while emacs is loaded, or when some special process is ongoing. I think Compilation is a good example, but I yet study it. Basically, it overloads some global short cuts to allow user to navigate around errors and warnings of compilation process.
As soon as we will create package for our custom code - we will introduce
mode-local keymap and fill it.

Bind on Emacs start

First, let's try binding our function on start up:
01 (global-set-key [?\C-x ?t] 'kill-whitepaces)
now, you can call this function any time, by just clicking Ctrl+x t.
Usually, we need this function in, say, java files. so we can add this to java hook:
01 (defun special-java-functions ()
02   (kill-whitespaces)
03   (local-set-key [?\C-x ?t] 'kill-whitespaces))
04
05 (add-hook 'java-mode-hook 'special-java-functions)
This brings us to the point, where we open java files, and automatically clean it. But if something strange happens - we still have short cut to remove trailing spaces.

Packages

Now, we want to spread our code around our own Emacs instances at home, and on the workplace, and maybe even in our cellphone. Further, other people might think that your code is not so useless, and wish you share it. Here packages come to help us.
All packages are stored in some repository. There is a default one - http://elpa.gnu.org/. To view list of available packages you can type M-x package-list-packages. Our goal is to have our own package in this list.

Upload package manager

To help us working with package repository, Emacs has package-x library. If you wish to update your repositories from some computer - load it in your configuration file:
01 (require 'package-x)
Remember, you will need this package only on development computer.
Now we need to create a repository. Usually, this is some remote directory, or http service. We will use local directory for now. Lets say it's name is /home/xaero/.emacs-own-packages/. To tell Emacs, that we want to use it, we should add next line to initialization file:
01 (add-to-list 'package-archives '("home packages" . "/home/xaero/.emacs-own-packages/"))
Note: You do not need package-x to work with package-archives alist.
This tells Emacs, that there is a repository, we name it "home packages", that we are interested in.
To tell Emacs, that we also want to upload new or newer packages into the same repository, we need to set package-archive-upload-base variable:
01 (setq package-archive-upload-base "/home/xaero/.emacs-own-packages/")
Now, when you will upload your packages, they will go into this directory.

Http resources

To make a read only package archive, you have to have ssh access to some remote host, and you have to set package-archive-upload-base to, say, ssh://remote.host.com:local/path/to/packages/. Emacs will be able to use it.
To make it reachable from the internet, you can set it available through http server from the http://public.host.com/packages/, and add this address into package-archives alist.
As we can see - URLs are different, but rights are not the same as well. If you will give access to ssh to some people - they will be able to modify your packages, while all the other people will just download and browse them.

Basic package

Package name should be short and verbose. Let's say whitespace manager, and shorten it to wt-manager. Single file package usually is held in single .el file with the same name as package. in our case - it is wt-manager.el :

01 ;;; wt-manager.el --- Manage file whitespaces
02
03 ;; Copyright (C) 2013 dimalev, Inc.
04
05 ;; Name: wt-manager
06 ;; Author: D. Lev. <ldimat@gmail.com>
07 ;; Version: 0.1
08
09 ;;; Commentary:
10
11 ;; Basic tools to manage annoying or required whitespaces.
12
13 ;;; Code:
14
15 ;;;###autoload
16 (defun kill-whitespaces ()
17   "Let's doc it"
18   (interactive)
19   (save-excursion
20     (goto-char 1)
21     (replace-regexp "[\s\t]+$" "")))
22
23 ;;; wt-manager.el ends here

Comment on line 23 is very important - Emacs will fail if it does not find one. Also characters after the end of file are not welcome. Most of other lines speak for themselves, except for line 15, which is autoload marker.
Emacs does not load all the extensions at the same time. It uses lazy load. For most of packages it loads only cover of the package, like main functions, which are meant to be called. As soon as you call one of such functions - it is loaded, and all the dependant code is loaded as well. So basically, if you will not mark some function for autoload - it will stay invisible, until the package is loaded after calling some function which is marked for autoload.

Upload and download

Now, just push this buffer into your repository (this is just a folder for us) by calling:
M-x package-upload-buffer
You can use package-upload-file as well, this does not change much, just that usually you will use file for multi-file packages. You can search information on multi-file packages and how to cook them on emacs wiki.
In case if you cannot find such a function - make sure you required package-x in init file, and reloaded your Emacs instance.
If everything is ok - then in your /home/xaero/.emacs-own-packages/ directory you can find your file with version suffix - like wt-manager-0.1.el as well as some other repository-related files.
Now, we have to download/upgrade our library in Emacs - go and type M-x package-list-packages and then search for wt-manager! To mark package for installation -  click i on it and then commit your choice by clicking x. All the files will be installed (you might be warned about replace-regexp used only in interactive environment, but come on - we are in it. I will fight this later), and you will be able to use kill-whitespaces function!

Multi-file packages

This is much more convenient way of distributing your code, so go and study how to use it: Multi-File Packages on Emacs Wiki

Links

[1] Packages on Emacs Wiki
[2] Keymaps on Emacs Wiki
[3] Key binding conventions

среда, 20 ноября 2013 г.

Emacs interractive functions for everyday use.

Abstract


Working with source files I prefer having all the white spaces and non viewable symbols being actually visible to me. This is useful to not mix spaces and tabs in source code, not leave trailing spaces, and especially handy it became when I had to work with yml files. They are very sensitive to tabs - files were just not imported by ruby library without meaningful message.
So, whitespace mode is permanent for my workspace in emacs. But there are people, who are not so pedantic to this question. Especially eclipse users (developers, they call themselves some times ;) ). Result is that opening simple .java file I get ton of red-highlighted trailing tabs and spaces, and I have to clean them somehow.
Any developer can solve this trouble with single regular expression, and we will watch how easy this is in emacs, using emacs lisp.

Disclamer

First, people who use eclipse can be good developers.
Second, I believe there is better solution in emacs to fight with trailing garbage, but I did not find it yet. And actually the fact that I can write this kind of functionality on the fly in emacs, makes it choice of mine.

Phase 1. Develop.

First, we have to check if our regexp works well, and would be good to evaluate future code just now. Emacs allow us to do that. M-: shortcut spawns "Eval:" prompt for us, so we can just put our code there. We just push
Eval: (replace-regexp "[\s\t]+$" "")
As we can see - all the trailing spaces are gone!

Phase 2. Integrate.

Now, we would love this piece of code to:
  1. Be available on the fly.
  2. Run every time when we open java source code.

Emacs load routine

First, we have to know, what emacs runs when it is started. ~/.emacs.el it is. Second, where should we put our custom code? ~/.emacs.d/ it is.
So, let's say, we will work on file ~/.emacs.d/whitespace-killer.el and load it using:
< style="background-color: black;">01 (add-to-list 'load-path "/home/dima/.emacs.d/")
02 (load "whitespace-killer")


First line of this code should be already present in your config file. It might differ - move you file with custom code accordingly, or you can add this line as well - this will not harm.
Second line loads .el file from available 'load-path alist. Read about alists.

Interactive functions

Inside whitespace-killer.el file we can define our function:
01 (defun kill-whitespaces()
02   (interactive)
03   "Removes all trailing spaces in the current buffer."
04   (replace-regexp "[\s\t]+$" "")
05   )

On the first line we define our function with the name, we wish to refer it.
Second line says to emacs that this function will be exported to use together with M-x family of calls. Basically, after this we can call it by typing:
M-x kill-whitespaces
Third line is optional, it is called document line. Emacs documentation tools use it to describe functionality of the function.
Next, goes body of the function. It is not flawless. Among it's drawbacks we can outline the fact, that it will be applied to code only after the current caret position. Other pretty bad thing, is that it actually leaves cursor after the last replacement.
These bugs are not a big deal, we can easily over come them. But we are not interested in this right now.

Hooks

As java file is opened, so-called java-mode-hook is fired. We can stick to it, and run arbitrary code:
(add-hook 'java-mode-hook 'kill-whitespaces)
So, next time you open java file - you will see no trailing whitespaces.

Phase 3. Debug.

What if emacs does not want to load after you do all the instructions? This happens, don't worry, just add --debug-init flag to emacs invocation command:
[dima@work java-project]$ emacs --debug-init Some.java
Observe the output:
Debugger entered--Lisp error: (file-error "Cannot open load file" "whitespace-killerff")
  load("whitespace-killerff")
  eval-buffer(#<buffer  *load*> nil "/home/dima/.emacs.el" nil t)  ; Reading at buffer position 1060
  load-with-code-conversion("/home/dima/.emacs.el" "/home/dima/.emacs.el" t t)
  load("~/.emacs" t t)
  #[0 " \205\262

and fix the problem. This time I don't have file whitespace-killerff, well, this happens - just rename the file, or fix typo.

Final code.

01 (defun kill-whitespaces() 
02   (interactive) 
03   "Removes all trailing spaces in the current buffer." 
04   (save-excursion
05     (goto-char 1)
06     (replace-regexp "[\s\t]+$" "")))

Useful links

[1] Hooks
[3] Alists