Search

Tutorials, tips&tricks, snippets..

#KISS: KEEP IT SIMPLE, STUPID!

Set Current Directory For Windows Service

By default, the current directory for your Windows service is the System32 folder. I keep forgetting that which causes me problems when I try to access a file or folder using a relative path.

System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);

Use the above line of code to set the current directory to the same directory as your windows service.

Create and install a Windows Service from a .NET Core project

Creating a Windows Service was the domain of the .Net Framework. However, since the release of the Windows Compatibility Pack that has all changed. There are no “New Windows Service (.Net Core)” options in Visual Studio, so how can we reach the goal?

Continue reading “Create and install a Windows Service from a .NET Core project”

Convert a p12 DevExpress/DevExtreme certificate to a keystore one

I use DevExtreme from DevExpress to build multiplatform app.

Since DevExtreme doesn’t support anymore its building tool, I use it only to create a zip package and then I build it with build.phonegap.com.

I had to upload my p12 file in this site, but first I had to convert it correctly.

This command line reached the goal:

keytool -v -importkeystore -srckeystore android_certificate.p12 -srcstoretype PKCS12 -destkeystore myKey.keystore -deststoretype JKS

After you run this command, in the output you’ll see the certificate alias. Use this to import the file in build.phonegap.com. If this is wrong, you’ll get an error while compiling the apk.

Create an iOS certificate and use it on build.phonegap.com

You can create a multiplatform app with Phonegap. At https://build.phonegap.com you can also compile the app and generate ipa/apk files. If you want, of course, to publish it on iTunes/Google Play you have to use a certificate. Here, how to create&use an iOS certificate.

Continue reading “Create an iOS certificate and use it on build.phonegap.com”

C# core: how to generate a pdf from a html with a xsl stylesheet as base64 stream

My goal was to create a base64 string representing the pdf, then send it to my mobile app and show it to the user (here for more info).

The following code is written using the Select.HtmlToPdf.NetCore package.

Continue reading “C# core: how to generate a pdf from a html with a xsl stylesheet as base64 stream”

Download&open a pdf base64 encoded in Android/iOS cordova/phonegap app

In my app, I need to download a pdf file from my api (base64 encoded, here how to create it), convert it and finally open it. Here how I made it.

Continue reading “Download&open a pdf base64 encoded in Android/iOS cordova/phonegap app”

String replace in SQL Server database table

Here a fast snippet

update my_table
set path = replace(path, 'oldstring', 'newstring')

If useful, you can also set a where condition.

Round number keeping trailing decimals without using string

I need all values to rounded to 8 decimal places. So, for example, 1.2 should round to 1.20000000, but Math.Round(value, 8) rounds to 1.2.

I’m using a C# class to populate and then serialise to xml. One of the values is a double. If I assign a ‘1.2’ to the value this gets serialised to ‘1.2’ when I actually need ‘1.20000000’.

I found this fast way to do this without converting the number to string:

foo = doubleValue + 0.00M;

And that makes the value 1.20000000 instead of just 1.2. This was better then doing a ToString and then parsing it back.

Disable onClick after first click to avoid double (or more) clicks

In my app (but this is valid also for web app), I have a problem: if user clicks twice (or more), twice requests (or more) are sent to the API server. Here a snippet to avoid this behavior with useless requests.

var pending = false;

function Foo(param)
{
    // test to see if something else set the state to pending.
    // if so... return, we don't want this to happen.
    if(pending) 
        return;

    pending = true; // raise the flag!

    /* ... later ... */
    // in the success method of your AJAX call add:
    pending = false;
}

Website Powered by WordPress.com.

Up ↑