Every once in a while you need to have access to a json api from another domain.

Thankfully there’s a mechanism to allow this. This Mechanism is called CORS

So before any JSON request is allowed a Options requst will be sent to the corresponding ressource and expects a „Access-Control-Allow-Origin“ header to be present.

There can be different values set for this which is explained in the linked article.

To enable this globally for a NancyFX Module you have to put the following code into it.

Hopefully this will help some folks out there

As I needed to export some data to an xlsx (Excel 2007+) file I first used the Microsoft OpenXML library called DocumentFormat.OpenXML.

At first it look good but had some major performance issued while using the object oriented style. I switched over to the OpenXMLWriter (SAX) but this introduces another class of problems like corrupted files. The Documentation is a pile of shit and after some while i gave up and reimplemented my export with NPOI.

To have it a little simpler i wrote some helper functions to do the cell and row injection. The result is as follows.

 

 

I had to implement a copy to clipboard functionality for our Control Panel which lists Orders.

Since I’m a total enemy of flash I pursued a solution suitable for my needs and here it is.

This is based on http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript but I removed most of the styling and simply put the textarea outside of the viewport.

 

>> The Code!!

First create the helper function in your controller (this can be move to a helper service as well if you wan’t)

 

And now simply bind it to your Element like this

This solution currently supports the following browsers.

Desktop:

  • IE 9+
  • Firefox 41+ (below that you have to enable copy in the user.js but since it’s enabled by default in the next Stable I don’t really care)
  • Chrome 42+
  • Opera 29+
  • Safari has no support for this sadly 🙁

Mobile:

  • Chrome for Android 42+
  • Firefox Mobile 41+

I’m quite happy with this and maybe someone will find this useful.

 

Well it has been a long while again, but I’ve been crazy busy at work.

I worked on a couple of interesting Single Page Applications written with Angular and I really like it because the Framework is so simple to use and very well documented with a crapload of nice plugins and extensions from the community. Anyhow I needed to implement some sort of internationalization and angular has a nifty extension called angular-translate which I used for that. In the process we created an i18n self hosted service in c# with nancy with a simple rest api where I can get a list of available languages for specific domains. Domains in this context are just language sections so that I only have to request and transfer the sections actually in use. The angular plugin has a nice way of supporting it with „partials“

so include the partials-loader and url-loader for angular-translate and set it up the following way:

 

This sets up the angular-translate plugin to work with partials which are loaded on demand from an rest service.

Since we are lazy we wanted to have some sort of automatically adding missing translations to the system.

The registered function in useMissingTranslationHandler handles this for us.

The handler is implemented as a angular factory and sends missing translations to a Model which hols a queue to bulk insert the translations to the i18n service.

This is done since we would exceed the allowed number of ajax connections on large applications at the first startup

I’m quite happy with this solution even though I think it has some room for Improvement.

Well it’s a long time since I last postet something here. Sadly i’ve been very busy with work and afterwards just coded for about an hour before going to sleep.

So what’s going on you might ask. Ive startet a rewrite of an unfinished project called AMVScore back then. The project startet because a friend of mine who hosts the AMV Contest and at some allowed the people watching in the big concert hall to vote for the vid via Twitter. This became quite popular and it became quite much a pain (at least that’s what you might guess when you speak to him) to count all those votes. After the last convention I simply told him I will write him a tool which will pull the tweets from twitter and processes them. I hacked something together in about 3 days after the convention which would work well enough but never got to a stage where I really would count on it since I always wanted to rewrite it in Yii2 for a learning purpose. So i posponed the developement until a final release of my favorite php framework. And here it is. It’s now called TwitterContestScore since it can be used for any kind of voting contest on Twitter. It’s nowhere near finished since I’m developing this on a more or less daily basis after work, but I will most definitely finish it until before the next convention.

Because this whole thing is a yii2 learning project for me I will try to post „nice to know“ bits and pieces and I hope you will like it.