Solving development problems  |  About this blog

Archive for the ‘Tips and Tricks’ Category

The easiest way to generate a QR Code for software developers

So you want to simply generate a QR Code image without diving into the technical specifics? This blog post contains a few simple examples. Just copy-paste where you need it.

Idea is to build a URL, make an HTTP request and download the QR Code image. Result is the following image:

your content goes here

HTTP Request

URL looks like http://www.esponce.com/api/v3/generate?content={content}&format={format} where {content} is URL encoded content to be embedded in QR and {format} is output image format. Available formats are png, jpg, bmp, tif, xaml, svg, eps, txt, html, zip (containing all listed formats)

List of other parameters like color and size can be found here.

C# Sample

This code can be used in .NET 2.0 including ASP.NET and WPF or Silverlight for web or WP7

using System;
using System.IO;
using System.Web;
using System.Net;

public class Program
{
  public static void Main(string[] args)
  {
    //Generate a QR Code and save it to file "sample.png"
    Generate("your content goes here", "png", "sample.png");
  }

  public static void Generate(string content, string format, string path)
  {
    string encoded = HttpUtility.UrlEncode(content);
    Uri uri = new Uri("http://www.esponce.com/api/v3/generate?content=" + encoded + "&format=" + format);
    WebClient client = new WebClient();
    client.DownloadFile(uri, path);
  }
}

Java Sample

This code can be used in a classic Java application or web applet or Android application

import java.io.*;
import java.net.*;

public class qrcode
{
  public static void main(String args[])
  {
    //Generate a QR Code image and save it to file "sample.png"
    generate("your content goes here", "png", "sample.png");
  }

  public static void generate(String content, String format, String path)
  {
    try
    {
      String encoded = URLEncoder.encode(content, "UTF-8");
      String url = "http://www.esponce.com/api/v3/generate?content=" + encoded + "&format=" + format;
      BufferedInputStream ins = new BufferedInputStream(new URL(url).openStream());
      FileOutputStream fos = new FileOutputStream(path);
      BufferedOutputStream bos = new BufferedOutputStream(fos, 1024);

      int size = 0;
      byte data[] = new byte[1024];
      while ((size = ins.read(data, 0, 1024)) > 0)
      {
        bos.write(data, 0, size);
      }

      bos.close();
      fos.close();
      ins.close();
    }
    catch (Exception e)
    {
    }
  }
}

Python Sample

Using Python 2.7

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import urllib
import httplib

def generate(content, format = "png"):
    query = urllib.urlencode({ "content": content, "format": format })
    con = httplib.HTTPConnection("www.esponce.com")
    con.request("GET", "/api/v3/generate?" + query)
    response = con.getresponse()
    image = response.read()
    con.close()
    return image

image = generate("your content goes here")
file = open("sample.png", "wb")
file.write(image)
file.close()

JavaScript Sample

JavaScript in combination with HTML

<img id="qrcode" src="" alt="QR Code" />
<script type="text/javascript">
    function generate(content)
    {
        var url = "http://www.esponce.com/api/v3/generate?content=" + encodeURI(content) + "&format=png";
        var img = document.getElementById("qrcode");
        img.src = url;
    }
    generate("your content goes here");
</script>

PHP Sample

<img src="<?php echo generate("your content goes here"); ?>" alt="QR Code" />

<?php
function generate($content, $format = "png")
{
    $encoded = urlencode($content);
    $url = "http://www.esponce.com/api/v3/generate?content=$encoded&format=$format";
    return $url;
}
?>

There is more

Download all samples with make script here.

Other QR Code related methods like decoding (reverse process of generating) and tracking scans can be found at esponce.com.

Written by developer

January 24th, 2012 at 3:46 pm

Visual Source Safe Analyze and Repair tool problems

This is the solution if you got this error message when trying to do Analyze and Repair some VSS database using does prompt command:
C:\>”C:\Program Files (x86)\Microsoft Visual SourceSafe\analyze.exe” -F -V3 -D “\\my_server\my_vss_database\data

Error was:

Database analysis in progress File ../data/status.dat is already open Cannot rebuild the database while Visual SourceSafe is being run. Make sure all users have exited SourceSafe and try again.

Solution

Make sure there are no users connected to the VSS database (running ssexp, ssadmin, etc), that users cannot connect to the database using the web service (they connect only for short times, so it’s hard to see them listed as logged in with ssadmin), and that VSS LAN Service is stopped (use net stop ssservice), as it may keep a connection open to the database.

How to disable the Thunderbird new mail notification window?

If you having a presentation and don’t want everybody to see e-mail popup with subject and message intro you can disable Thunderbird notification window that appears above System Tray (bottom right) by doing these steps

  1. Click Tools and select Options
  2. Select the General tab
  3. Click the Config Editor button
  4. Search for biff
  5. Set mail.biff.show_alert to false

Written by Avivo

September 29th, 2011 at 8:31 am

Windows 7 – Fix if SLEEP mode does not work

Check your network card properties through the device manager and disable the “Allow this devide to wake the computer” feature.

  1. Right click on your “My Computer” then select Properties.
  2. Click Device Manager on the left side of the Properties window.
  3. Check your Network card on the Network Adapters (Click on the + sign to expand).
  4. Right click on your network card and select properties.
  5. Go to the Power Management tab and untick the option there to prevent your network card from ever waking up your Windows.

Find out what wakes up your Windows 7/Vista from its sleep

To find out what event/device woke up your Windows from its sleep state, go to command prompt (type cmd on the Run/Search box and press ENTER), then type this:
powercfg – lastwake

 

To get the most detailed info (and probably easiest) on the device that wakes your Windows up during the sleep, type:
powercfg –devicequery wake_armed

 

There! You’ll find the culprit I clicked my mouse to wake my Windows up intentionally so that’s why you see an HID compliant mouse on the screenshot above. Yours might be different.

Hope this helps to prevent your computer wakes up from sleep by itself!

If it still doesn’t work:

  • Check out your Power Management Options on your Control Panel (Start, Control Panel, Power Settings, Change plan settings, Change advanced power settings).
    -> “Multimedia settings” option, “When sharing media.” ->”Allow the computer to sleep.
    -> Check other options one by one while you’re at it.

Original article available here.

Written by Avivo

September 11th, 2011 at 9:33 am

Seeing iTunes purchases and about 1$ credit card’s authorization holds

In order to see all your iTunes purchases follow these steps: http://support.apple.com/kb/HT2727

When you sign up for your AppleID and provide your credit card information Apple will try to check validity of your credit card and will create few 1$ authorization holds on your credit cards:

You might see such authorization requests on your online statement.
These requests are not actual charges; they are tests to confirm that your credit card
account is active and has credit available to accommodate transactions.
Authorization holds are removed by your financial institution shortly after
your purchase clears. The amount of time it takes to remove authorization requests
varies by financial institution.

To review the actual charges on your account, you may review your iTunes Purchase History.
You will be prompted to enter your iTunes account name and password.
Note that Mac App Store web order details can only be seen in the iTunes purchase history.
Your Purchase History will display your most recent purchases first.
To view details of any purchase, click the arrow to the left of the order date.

If you have questions about the way your financial institution handles authorization
requests, please contact their customer service department.

Written by Avivo

August 17th, 2011 at 2:46 pm