Tag Archives: how to

Create a basic project structure with Electron Forge


Electron is GitHub’s cross platform desktop application development tool powered by Nodejs , CSS and HTML.

Electron Forge

What is Electron forge ? Electron Forge is a programmer’s tools to help create , build electron application quickly as possible.

First up all you need to Install Nodejs and then install electron forge from terminal

npm install create-electron-app -g 

Now you are ready to use the tools.

Basic Electron Project Setup

Let’s create a project with basic structure which includes

  • index.css
  • index.html
  • index.css
  • package.json
  • nodemodules

open your terminal and fire up

npm create-electron-app  myapp

It will take some time to generate files and you are ready to first run npm start

For more information and guide have a look at Official Site

 

 

Create a basic project structure with Electron Forge


How to quickly create a sample project with necessary folder and files structure Nodejs Electron

Book Keeper Free


Download Book Keeper Personal Edition – A accounting package for Windows users

Display post inside another post/Page in WordPress


We have learned so far how to use listing projects with short codes , with content, excerpts, image and lots of customization. If you ever miss them here it is

Post inside a Post

Place a post inside another post or page.  Sound crazy ? You can do this with Display-posts plugin which can be used as short code .

Do you know that you can place short code  not only in  short code block but also a paragraph block or in classic editor  as [ short code here].

First we have to find the post ID ( each WP post comes with unique post id, you can find them in posts by pointing the post title, in the status bars it will show as post=2005)  , since we need a single post and use it in short code as follows.

As we all know short code appear inside of opening( [ ) and closing (]) square brackets.

Short code
display-posts id=2419 include_content=true
[ short code here ]
display-posts

display-posts – Example

Using the id  we can specify the post ids, in case of multiple post separate with comma (,) , also want to show content after the title , so used the include_content option which is by default set to false.  

 

Display random projects using short code block in WordPress


We have seen how to use short code to play with portfolio projects, I have few more posts in this category.

How about a random wise project list , in a page or post, which changes the order each time load. A customization of short code will make it possible

portfolio showposts=3 orderby=rand

You can specify number columns using columns parameter and number of posts using showposts parameter

  • display_types: display Project Types – displayed by default. (true/false)
  • display_tags: display Project Tag – displayed by default. (true/false)
  • display_content: display project content – displayed by default. (true/false)
  • display_author: display project author name – hidden by default. (true/false)
  • include_type: display specific Project Types. Defaults to all. (comma-separated list of Project Type slugs)
  • include_tag: display specific Project Tags. Defaults to all. (comma-separated list of Project Tag slugs)
  • columns: number of columns in shortcode. Defaults to 2. (number, 1-6)
  • showposts: number of projects to display. Defaults to all. (number)
  • order: display projects in ascending or descending order. Defaults to ASC for sorting in ascending order, but you can reverse the order by using DESC to display projects in descending order instead. (ASC/DESC)
  • orderby: sort projects by different criteria, including author name, project title, and even rand to display in a random order. Defaults to sorting by date. (author, date, title, rand)

How to add to post/page

  • Add a short code block
  • Add the customized portfolio code [Above]
  • Preview and Publish changes

More on WordPress and Short Code

Display specific type of portfolios using Short Code in WordPress


How to display only specific portfolio projects in a page/posts using short code block in your WordPress website ?

Portfolio short code can be customized. Following are the list of attributed you can use

  • display_types: display Project Types – displayed by default. (true/false)
  • display_tags: display Project Tag – displayed by default. (true/false)
  • display_content: display project content – displayed by default. (true/false)
  • display_author: display project author name – hidden by default. (true/false)
  • include_type: display specific Project Types. Defaults to all. (comma-separated list of Project Type slugs)
  • include_tag: display specific Project Tags. Defaults to all. (comma-separated list of Project Tag slugs)
  • columns: number of columns in shortcode. Defaults to 2. (number, 1-6)
  • showposts: number of projects to display. Defaults to all. (number)
  • order: display projects in ascending or descending order. Defaults to ASC for sorting in ascending order, but you can reverse the order by using DESC to display projects in descending order instead. (ASC/DESC)
  • orderby: sort projects by different criteria, including author name, project title, and even rand to display in a random order. Defaults to sorting by date. (author, date, title, rand)

Display only specific post types

You can specify post types as include_type and it will look like

portfolio include_type="Flutter"

You can also hide showing display type by using display_types=false false

Use word template with Xceed.Docx


Xceed.Words.Net is a library for generating word file without using the office library. You need not to install the office for create word file from your C# application.

I have plenty of beautiful Microsoft template, which I used create reports. So what I need is to use those template with Xceed. The idea sound good, isn’t it.

Lets place all your templates inside folder, in your debug folder and use it in your Xceed code as follows

using (var document = Xceed.Words.NET.DocX.Create(fname))
{
 document.ApplyTemplate(@"doctemplates /CashLedger.dotx");
document.ReplaceText("[MyCompany]", ViewModels_Variables.ModelViews.CompanyProfile[0].company);
                    document.ReplaceText("[Clandmark]", " | " + ViewModels_Variables.ModelViews.CompanyProfile[0].lmark);
                    document.ReplaceText("[CCity]", " | " + ViewModels_Variables.ModelViews.CompanyProfile[0].place); 
document.Save();
document.Dispose();}

My template folder simply named templates and use @”doctemplates /CashLedger.dotx” to locate the application path folder.

Here is a sample document template

How to pass python list to JavaScript in Flask app


You can’t use Python list directly into JavaScript, JavaScript lislt/array is not compatible with Python or wise versa. So what to do.

Solution

I have a list of names, which I want pass to a JavaScript in a Flask ninja template. Ninja template allow use to safely convert the python list to Json string then we can pass it to the JavaScript function / just JavaScript

<script type="text/javascript">

        dn = {{ distabr|tojson }}
</script>

You can’t use same route variable in multiple places in same template, it may not serve the purpose

In JavaScript Functions

Suppose you have separate JavaScript function files for some functionality like drawing analytic plots and pie diagram, or some donut chart. So how do we pass value to those functions ?

You can create a JavaScript as above, in your current template, then in function create a script variable to use it as follows.

function init_echarts() {
    var distNames=dn;
}

That’s all you need to know to embed some morris diagram to your flask app.

You should look at Morris JS , it is free and easy to use JavaScript charts library.

How to INSTALL DJANGO ON WINDOWS 7?


‘Django’ was one of the popular Python framework, which can be used to create beautiful dynamic website from scratch. Write less and do more that is the frameworks mean to. You don’t need to start from the beginning, Django will take care of that.

How to get my copy of Django?

Well, it is a free framework free of cost, you can download and use Django 1.6.5 or later along with Python 3.3 or prior version on Windows/Linux/Mac or on almost any Computer OS.

Installing Django on Windows 7 and later

Make sure that you have latest Python version installed on your computer. You can download it from Python.org. Extract the Django .Zip/.tar file, using Winzip or 7zip (preferably C:/, root directory).
Setting Python paths on windows will let you run it from any drive, learn how to.
Let’s install the Django, issue the following command using Power Shell or command prompt (Run->PowerShell).

C:/> CD django1.6.5
C:/>django1.6.5> Python setup.py install

And it will run the python script for installation. All file required will be automatically copied to the Python Lib\site-package folder securely. After the process you can safely delete the extracted folder from the C:\ drive.

Installing Django on Linux

On Linux you have prebuilt Python on it, so no need to install it separately. Just extract Django .tar file and run the setup script.
Verifying the Django installation

Run the following on Python prompt

>>> import django
>>> print (django.get_version())

Will result in displaying the current version as (if everything went right)
1.6.5

That’s all

How to use common folder paths in C#


Reading files from application path may be one of key requirement of any application. Actually we can place many place you love to have, on a installation machine there can be restriction as well.

Like wise in a Windows system, installer may want to put apps and other files to Programfiles. This folder intended to work with executable,configuration files etc. You can’t programmatically create new folder or files in Programfiles folder, which may require some admin rights. So where we kept those documents and other data ?

It is wise to store such files on Application data folder or even on your Document folder. For reports and other stuffs Document folder is enough.

Access Special Folders

We can use the Enironment.SpecialFolder to access the App data and Documents and also can fetch path to those folders using GetFolderPath method of Environment class.

datapath = Environment.GetFolderPath(Environment.SpecialFolder
.ApplicationData);
reportPath = Environment.GetFolderPath(Environment.
SpecialFolder.MyDocuments);

the first line will get the location of C:\Users\manoj\AppData\Roaming and the second will show the Document folder path .

Access application path

How to access application/executable path in C#. This can be done using Application.ExecutablePath and the GetFolderPath method

 Path.GetDirectoryName(Application.ExecutablePath);

How to set background image using ImageBrush in C# WPF


Back ground in WPF application can be set using XAML at design time or at run time. Using XAML we do it as follows

 <Window.Background>
        <ImageBrush ImageSource="images\abstract-art-artistic-background-1103970 (1).jpg"/>
    </Window.Background>

At Runtime

Using some code you can change back ground of WPF /C# application using ImageBrush and BitmapImage object as follows

  • Create Uri ,which defines the path of the image
  • Using Uri define a bitmap image object which can source for ImageBrush
  • Create a BitmapImage object and set the ImageBrush source
  • Set Background property with ImageBrush

All the above can be done with inline code as follows

 ImageBrush imageBrush = new ImageBrush(new BitmapImage(new Uri("D:\images\abstract-art-artistic-background-1103970 (1).jpg",UriKind.RelativeOrAbsolute)));
                this.Background = imageBrush;

Add records to SQL DB using command builder and dataset in C#


When I talk about C# Dataset quote that it can also be used for insertion of data into the table too. In this post, we are going to learn how to.

Prerequisites

  1. Data connection with SQL
  2. Dataset
  3. Command builder object

In our example, we had MiniPurchaseInfo table and dataset associated with it.  First thing first, the dataset

SqlDataAdapter MiniPurchaseInfo = new SqlDataAdapter("select * from minipurchaseinfo", con);
 MiniPurchaseInfoDataSet = new DataSet();
 MiniPurchaseInfo.Fill(MiniPurchaseInfoDataSet, "minipurchaseinfo");

We simply make the query, filling the information to the dataset and so on. The next step is to create a row with the DataRow object and add the data row to our dataSet object.

DataRow dro;

dro = MiniPurchaseInfoDataSet.Tables[0].NewRow();
 dro["entryno"] = entryNo;
 dro["supinvoice"] = txt_invoice.Text.ToString();
 dro["supid"] = SUPID;
 dro["netamount"] = net;

add the row to the dataset.

MiniPurchaseInfoDataSet.Tables[0].Rows.Add(dro);

The final step is to set up the command build which has the capability of insertion and deletion operations with DB adapter and dataset.

System.Data.SqlClient.SqlCommandBuildercmdbuilder = new System.Data.SqlClient.SqlCommandBuilder(MiniPurchaseInfo);

Set insert command of the adapter from the command builder object

MiniPurchaseInfo.InsertCommand = cmdbuilder.GetInsertCommand();

Call the update command of the adapter which will update the new row stored in the dataset into the database table.

int r = MiniPurchaseInfo.Update(MiniPurchaseInfoDataSet.Tables[0]);

The update will return a none zero value when the insertion performed.