Skip to main content

Posts

Authenticate OpenXava users with ActiveDirectory

The following allows you to use JNDIRealm 's LDAP authentication to authenticate users of OpenXava application with Active Directory. The users will be prompt to enter their windows credentials, when entering the usernames they need to avoid entering the domain name; they just need to enter the username. If you have multiple Active Directory domains to authenticate against, you can use  org.apache.catalina.realm.CombinedRealm to allow Tomcat to search on both. In the web.xml you will need to specify the security-constraint setting. This will force the user to authenticate when they reach any OpenXava module. in role-name, you have to enter the Windows Group name of that is allow to access the application. If you need finer restrictions, you can use OpenXava's Users.getCurrent() to get the username of the current user in your Java code. For example, you could have a validation logic to prevent a certain user from creating a new record. Please note that you must use a ...

A Solution to the Marriage Dilemma

In the midst of the raging battle between those who want to legalize homosexual marriages and those who oppose it, a solution could be implemented that would fit the goals of both sides. The problem with the traditional marriage constitutional amendment is that it asks the Government for the wrong thing. Asking the Government to define marriage as one man and one woman is a huge mistake because it takes away that power from religion and puts that power in a Government that is already taking too much power. It is extremely important for the survival of the Church that the government stays away from her . If we let the Government take that power,  not only would break the first amendment, but it also would teach future Christians generations that it does not matter what the Bible says what marriage is, all it matters is what the Government says it is. The definition of marriage belongs to culture and religion and it should stay there.  Instead, I would like to propose the...

Construct2: surpassing GameMaker and Multimedia Fusion

I a few years ago, I posted an article about why I preferred GameMaker over Multimedia Fusion. A lot has happened since then, Clickteam released many exporters for MMF (Flash, IOS and others) and YoYo Games have made HTML5 gaming GameMaker’s new target. Another product has been in the works too, Scirra produced Construct2 as a HTML5 game maker. Just like I reached my conclusion back then through spending time on GameMaker, I have come to the conclusion that Scirra’s Construct2 is a very worthy contender to both by spending some time using it and writing plugins for it. Construct2’s main target is HTML5 gaming, however, it is straight forward to create exporters for it and I am actually working on a XNA exporter for it. I have also created plugins that allow Construct2 games to create simple 3D games (WebGL via Copperlicht), online multiplayer games (through websockets) and isometric games (through a Z sorter plugin).   Construct2 enjoys an easy-to-use event-driven inter...

How to create online multiplayer HTML5 games in Contruct2

  Construct2 can use websockets to send and receive messages between games. By using socket-io , we can use a Node.js script as the server and my modification to the socket-io plugin for Construct2 to allow the games to synchronize data between them in real-time. There are two parts to this design: the Node.js server and the Construct2 clients (the games playing). The main part of building an online multiplayer HTML5 game is to plan: how the clients will communicate how often and what to communicate how much of the logic will go into the server and how much to the client. In my sample game, I chose to have each client own a player and have the server just relay messages: Use string messages in the form TypeOfMessage, Parameter1, Paremeter2, Parater3, etc to communicate. Have the clients send their player position about 16 times a second. Whenever their player shoots, the client needs to send a message immediately. Almost all of the game logic will...

Prevent Visual Studio from using SQLEXPRESS when using Webparts

To prevent Visual Studio from using SQLEXPRESS when using Webparts and WebPartManger, you will need to override the "LocalSqlServer" connection string from your machine.config into your web.config file. To do that, add the following to the <connectionstrings> sections in your webconfig file: <remove name="LocalSqlServer"> <add connectionstring="data source=.\YOURINSTANCENAME;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" name="LocalSqlServer" providername="System.Data.SqlClient"> </add> Othwerise, if you do not have an instance named SQLEXPRESS in your machine, the page containing your WebPartManager will fail with the following error: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is co...

Using GAE OData from C#: Authentication

The last post about ODATA in the Google App Engine (python) allowed anyone to create, update or delete the models. Google App Engine (GAE) can authenticate Google users or users of you Google Apps domain. Using this feature, we can authenticate users of our C# application and use the authentication token when submitting calls to our OData service. The following class is based on the work found in  here . class GAEAuthentication { public string Authenticate(string gaeAppBaseUrl, string googleUserName, String googlePassword, string yourClientApp, string is_admin, bool is_dev_env) { string googleCookie; String gaeAppLoginUrl = gaeAppBaseUrl + "_ah/login"; String yourGaeAuthUrl = gaeAppBaseUrl + "odata.svc/"; String googleLoginUrl; if (is_dev_env) { googleLoginUrl = gaeAppLoginUrl; } else { ...
I am working on a plugin for Scirra's Construct2 that would allow users to present their C2 levels as 3D levels in copperlicht. Here is a demo so far: http://mathbattlegame.appspot.com/static/copperlicht/tutorial2/index.html I synchronize the positions and rotations between C2 and copperlicht, so copperlicht is just a "screen" for C2's logic. In the demo you see that you actually move and rotate the C2 sprite, and copperlicht is just being told to imitate the pos and rotation. This will allow you to use all the nice things from C2 and show them in 3D. You move by using the arrow keys and you can shoot "bullets" by pressing 'Q'.  I added the download to both the plugin and the demo at: https://sites.google.com/site/jptarqu/downloads  The name of the download is  copperlicht-c2-plugin-v-0.9.zip .  Please note that to run the sample capx, you will need to export it to your web server (either local server like IIS express, apache, etc. or to a external...

Uh???

I am so confused with the Ms. Fluke situation, I have no clue what is going on. Limbaugh says she is asking taxpayers to pay for her contraceptives; but then I read that she (as a customer) was actually asking her private insurance to cover them and not the Government, which is her right as a customer to ask from a private company. But the, if it is a private business issue, I don't understand why is the Federal Government getting involved? Then I also read that most private insurance cover Viagra, is this why medical bills are so expensive? is it because Insurers can't pay for them because the insurance pool money is being used to pay for Viagra pills? I also read that this all started when the federal government added the free-contraceptives requirement to insurance carries as part of the Universal health care plan. I still remember during the health care debate a few years ago, Hillary Clinton was asked how the plan was going to protect itself from bankruptcy by the peop...

Using GAE as a OData service for the data layer

One of the many challenges of software development is to allow your application to save its data into a reliable repository from anywhere in the world. With Google App Engine ( GAE ) and its cloud service, you can put the data layer of your application in the cloud and still use your preferred programming language to create your business and presentation layers. By exposing your GAE database using OData ( http://www.odata.org/ ), you get a flexible way of storing and retrieving your data from any desktop client or mobile application including C# based applications. The best thing is that GAE offers free quotas unlike Microsoft Azure's offerings. One OData library that I know works in GAE is odata-py (  http://code.google.com/p/odata-py/ ). After downloading the latest version (using SVN), you can start using the sample GAE application that comes with it. There is however, one small fix you need to make. Modify core.py to prevent an exception when getting the Key from the url when...

Convert PDF files to TIFF using power shell

You can use the following ps script to convert PDF files into TIFF files: $tool = 'C:\Program Files\gs\gs9.01\bin\gswin64c.exe' #the path to your Ghostscript program. $files_folder = 'c:\youfolderwithpdfs' $pdfs = get-childitem $files_folder -recurse | where {$_.Extension -match "pdf"} foreach($pdf in $pdfs) {     $tiff = $pdf.FullName.replace('.pdf','').replace('.pdf','') + '_-_p%03d.tiff'     if(test-path $tiff)     {         "tiff file already exists " + $tiff     }     else             {            'Processing ' + $pdf.Name                 $param = "-sOutputFile=$tiff"         & $tool -q -dNOPAUSE -sDEVICE=tiffg4 $param $pdf.FullName -c quit     } } The script creates one Tiff file per PDF page. There are other options inGhostscript that you can use. To get Ghostscript for wi...

There is already an open DataReader error and how to fix it

When trying to execute SaveChanges on a Entitiy Framework datacontext, I was getting the following error: There is already an open DataReader associated with this Command which must be closed first The problem was caused by the location of the SaveChanges call. The code called the method inside a ForEach loop that iterates through a result returned from a query. Because of the iteration the datacontext’s connection was on read mode and thus did not allow me to call the update. To fix it I moved the SaveChanges call outside the ForEach loop (when the read was completed: var records = EFDataRepository.GetAll ().Where(r => r.CreatedOn < cutoff_date); foreach (var record in records) { workflow.WorkAndUpdate(record); //repo.SaveChanges(); //do not put it here, you are still iterating over the results in read mode } repo.SaveChanges();

Attachment does not show in Outlook when sent from Cognos Report Server

If you use Cognos ReportServer and have a scheduled report that is sent by email, you may get into a peculiar problem when sending the report to recipients in an Exchange 2007: the attachment will not show if the recipient sees the email in his Outlook client. For some reason it will be displayed in any other email client they might use (smartphone, webmail, etc) but not in the Outlook installed in their desktop. A solution to this problem is to make sure the scheduled report contains text in both the subject and the body of the email being sent. You can do that from the email options in the Cognos when scheduling the report. You need to make sure the subject and the body is populated even if it is just a word. A clue to what causes this problem is found in the following link: http://www.eggheadcafe.com/microsoft/Exchange-Admin/31852947/exchange-2007-hidden-attachments.aspx

Friends Guess is now available in the Marketplace

My new Windows Phone 7 game, Friends Guess was recently approved in the Zune marketplace. It is now available to Windows Phones. To play Friends Guess you are given the name of one of your Facebook friends and then you have to match the name to one of six profile pictures in the screen. It is a fun way of keeping up to date with your friend’s profile pictures. You will be surprise at the pictures your friends choose for their profiles; I sometimes ask myself, “is that their profile picture now? no way…” when playing the game. The idea of the game came from wife, while we were driving back from our vacation in Virginia. There is a web based version of the game at http://friendsguess.appspot.com if you don’t have a Windows Phone. This web version should work on the iPhone too and possible Android phones (depending on your OS version). The web version has a slightly different scheme for scoring, but the mechanics are as fun as the Windows Phone version. From a programming perspect...

Idea: Separate non-violent inmates from violent inmates

Why do we put in the same jail violent criminals with non-violent criminals? As far as i know (please correct me if i am wrong), the current system sends non-violent offenders to the same place as violent offenders. Would it not be better to put nonviolent criminals to forced labor to repay their debts to society? I am thinking of large working camps, where they would be forced to labor 6 days a week on hard-work or dangerous places where manual labor is hard to find. These working camps would allow them to sleep in tents or some sort of cabins. Security could be minimal since there would be only non-violent offenders. Would any non-violent offender prefer to go to such a “working camp” than to go to a jail full of gangs and murderers? I would think they would love to have that choice. Separating violent from non-violent criminals would allow the Government to make penitentiaries across the nation less “cozy”. Let the violent criminals live in one cell (one per cell) and never allow ...

Using lambdas to wrap model validations in C#

In .NET, I have found the following method useful when wrapping validation around any CRUD operation: private IEnumerable<ValidationResult> PerformWithModelValidation(object model, Action code_to_execute) { var results = new List<ValidationResult>(); ValidationContext context = new ValidationContext(model, null, null); bool valid = Validator.TryValidateObject(model, context, results, true); if (valid) { code_to_execute(); } return results; } //How to use the method above: PerformWithModelValidation(new_product, () => { MyRepository.Add(new_product); MyRepository.SaveChanges(); } );

Powershell script for converting JPG to TIFF

The following Powershell script will convert a batch of JPEG files to TIFF format: #This Code is released under MIT license [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") $files_folder = 'C:\path-where-your-jpg-files-are\' $pdfs = get-childitem $files_folder -recurse | where {$_.Extension -match "jpg"} foreach($pdf in $pdfs) { $picture = [System.Drawing.Bitmap]::FromFile( $pdf.FullName ) $tiff = $pdf.FullName.replace('.PDF','').replace('.pdf','').replace('.jpg','').replace('.JPG','') + '.tiff' $picture.Save($tiff) }

Powershell script to list the binary paths of SQL Instances

You can use Powershell with WMI to find out the paths where the binary files of SQL instances reside. The following code will display the path to the binaries for each instance installed in a server (replace yourservername with your server name): SQL Server 2005: Get-WmiObject -ComputerName YOURSERVERNAME -namespace 'root\Microsoft\SqlServer\ComputerManagement' -query "SELECT ServiceName, BinaryPath FROM SqlService WHERE SQLServiceType = 1 and ServiceName like '%SQL%'" | ft -property ServiceName, BinaryPath SQL Server 2008 or SQL Server 2008 R2 : Get-WmiObject -ComputerName YOURSERVERNAME -namespace 'root\Microsoft\SqlServer\ComputerManagement10' -query "SELECT ServiceName, BinaryPath FROM SqlService WHERE SQLServiceType = 1 and ServiceName like '%SQL%'" | ft -property ServiceName, BinaryPath

C# code to parse an x9.37 file

The following C# code will parse an X937 file (Image Cash Letter) and get the amounts of each check // BigEndianBitConverter class taken from http://www.yoda.arachsys.com/csharp/miscutil/ // ConvertEBCDICtoASCII method taken from http://kseesharp.blogspot.com/2007/12/convert-ebcdic-to-ascii.html static void Main(string[] args) { var input = new BinaryReader(new FileStream("YourICLFile.icl",FileMode.Open)); byte[] amount_bytes, record_type_bytes; byte[] record_lenght_bytes = input.ReadBytes(4); var converter = new BigEndianBitConverter(); int record_lenght = converter.ToInt32(record_lenght_bytes,0); string record_type, amount_str; //Totals long check_items= 0, total_amount = 0; try { while (true) { //Get record type record_type_bytes = inpu...

How to extract data from MS Word dropdown fields

When converting a Word form to a web form, I was looking for a way to extract the items of the dropdown fields found in the Word document to avoid typing them manually in my web app. I found that you can access the field definitions from C# by using the Word  Interop COM library. The following is a program that extracts each item in the dropdown boxes and prints them to the screen: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Office.Interop.Word; namespace WordDataExtractTest { class Program { static void Main(string[] args) { Application wordapp = new Application(); var strDocName = "doc_file_with_form.doc"; var doc = wordapp.Documents.Open(strDocName); foreach( FormField form_field in doc.FormFields) { if (form_field.Type == WdFieldType.wdFieldFormDropDown) { Ad...

How to get the raw data posted to a Java Servlet

While working in porting GeneCMS to Google App Engine and Silverlight , I stumble at one annoying problem: how to get the raw data that was sent by the browser via a POST. In this GeneCMS port, the silverlight client actually generates all the HTML that the server used to generate. The raw generated HTML is then sent to the GAE application, with some metadata about the generated pages. The GAE servlet then reads the posted data as a string and extract the individual generated pages. Each generated page is then saved into the GAE database to allow the CMS to server the pages. After tweking around in the wrong places, I finally found out that HttpServletRequest’s getInputStream method is an input stream to the raw data posted. So I modified my servlet to get the POST data into a string like this: String posted_data = ""; BufferedReader in = new BufferedReader(new InputStreamReader( request.getInputStream())); String line = in.readLine(); while (line != null) { posted...