Showing posts with label Miscellaneous. Show all posts
Showing posts with label Miscellaneous. Show all posts

Thursday, May 24, 2018

Cage The Monster


Round: 1
Total Caged: 0
Easy Difficult

Thursday, December 24, 2015

Hello World Quartz Job

A few days back I needed to use Quartz for some task and I really struggled quite a bit to get running with my hello world quartz service. Now since I am up and running I thought to share and save an hour or two for someone else :)

Next are steps for creating a simple Hello World Quartz Job.

Step 1: Create a new windows service project in Visual Studio, you may also use an console application or whatever else you can think of :)



Step 2: Add Quartz to your project using nugget, you may add nugget reference or add quartz reference from somewhere else if you want. Doing nugget way is better it also automatically installs the required dependencies.














.

Step 3: Every quartz job has two important things, first is "what needs be done" and second is "when it needs be done"

To tackle first part that is "what needs be done", we need to create a class file to define Job. So add a new .cs file and name the class whatever your want. For this sample I'll take it as SampleJob. This class needs to implement IJob interface present in Quartz namespace.















Execute method as shown in above image comes when you implement IJob interface. Here in this sample I simply added a line to append some text to a text file.

To tackle second part that is "when it needs be done", check step 4

Step 4: Quartz provide two ways to schedule jobs, one is through code and other is using XML. Second approach is what I'll go with as I find it more useful. Here you will add an XML file and specify which job needs be executed and when it needs be triggered.



























In this xml file we do define job schedule, that is when a job needs be executed. For each job you want to schedule add one schedule node. Each schedule node will have their respective job and trigger nodes.

Under job node we have job-type node which wasted loads of time and prompted me to write this post. In this node we have two comma separated values, first one is class name of job that you want to schedule and second value is assembly name. Be careful here I firstly added namespace of Service class file with class name and banged my head for quite some time before figuring out why my jobs were not running.


Step 5: Next is to wire-up quartz scheduler with windows service/console app (or whatever else you are using), just add three lines in OnStart method as shown in below image












Step 6: For scheduling jobs using XML file you need to do a few configurations in App.config file, below are those settings













Value of setting with name quartz.plugin.xml.fileNames is path of jobs xml file(one that we created in step 4 above).

Now you are all set from coding side of things and ready to install your service. You may use whatever way you want to deploy windows service, I used installutil.exe utility for the same.

using installutil.exe:

1. Build your project
2. Open visual studio command prompt
3. Execute command
    installutil.exe
4. Now open service manager console using services.msc command in run box
5. Find your service and click start

That's it, you are done and your small hello world quartz job is up and running.


Merry Christmas :)

Friday, October 10, 2014

Windows Powershell Script - write to both console and file

Few days back I was writing my first power shell script and thought to write my output to both console and some logfile. Surprisingly it wasn't as simple I thought and I ended up doing this.
function logMsg($msg)
{
    write-output $msg
    write-host $msg 
}
usage in script:
logMsg("My Error Msg")
logMsg("My Info Msg")
powershell script execution call:
ps> .\myFirstScript.ps1 >> testOutputFile.txt

here write-host is to write to console and write-output takes care of writing to my log file.

Saturday, October 27, 2012

Rawan Dahan

Just for fun (working best in chrome and safari, works but is slow in IE and Firefox)

Missiles Fired: 0
Click bombs to drop
*
*
*
*
*
*
*
*
*
*
Rawan
ravan's head' ravan's head' ravan's head' ravan's head' ravan's head'

A simple game made just for fun.

How to Play:
  • Click missiles to fire them, time them such that they fall on Rawan's main head
  • You get 10 missiles by default and you have to strike rawan's head 5 times to win
  • Click "Reload drones" button to reset missiles, this will not restore number of rawan's killed
  • Click "Reset Game" button to reset game to initial values
  • Try this on Chrome or safari, as game speed is slow on Firefox and IE.
Images used here are not of mine.
Rawan's image can be found here.
Drone's image can be found here.

Thursday, May 24, 2012

using variables in css - CSS Pre-Processors

Have you ever felt that CSS should be more powerful, having variables, expressions, code reuse capability between classes and other such stuff. If yes then here is an option to do all that. I stumbled to it a few days back and found it to be quite impressive.
Less - The dynamic stylesheet language, lets you to specify widely used values in a single place, and then re-use them throughout the style sheet.

Below is a simple example of LESS code:

// LESS
@color: #4D926F;
#header
{
     color: @color;
}
h2
{
     color: @color;
}
/* Compiled CSS */
#header
{
      color: #4D926F;
}
h2
{
     color: #4D926F;
}

 LESS offers a lot more than this. To know more check their website...

Edit 28th Oct, 2012:

I just found that Less is not alone and its one of the members of family called CSS Pre-processors. I also read a very nice blog post from Miller H. Borges Medeiros illustrating some drawbacks of using these.

Thursday, July 7, 2011

The world is built on C++

Hi All,

"The world is built on C++", Herb Sutter

I am not a C++ developer but found below news to be interesting. This also created a question in my mind, how much these changes can accelerate growth of C++ usage, keeping in mind the current status of its rivals (Java, C#, etc). Please spare a few minutes to share your views on my question here.

Apple's Mac OS X, Adobe Illustrator, Facebook, Google's Chrome browser, the Apache MapReduce clustered data-processing architecture, Microsoft Windows 7 and Internet Explorer, Firefox, and MySQL – to name just a handful – are written in part or in their entirety with C++.

According to Sutter, C++ is on the verge of its biggest change in the 13 years since it became an official ISO standard, a change that will make it relevant for the next two decades.

The recently finished C++ ISO standard, with the working name of C++0x, is due to be published this summer, following the finishing touches to the ISO spec language and standards wonks agreed upon in March.

If you have read so far you might also like to have a look at this article from where I got this information and words ;)


Sunday, February 27, 2011

Extract images from Word files

A few days back I was in need to copy an image from a MS-Word document so that I can add it somewhere else. I thought that I would be able to copy/paste the image in ctrl+c/ctrl+v way, but it didn't worked. So I tried a rather unorthodox way. Steps I took are as below:
  • Saved my .doc file as .docx file
  • Changed the extension to .rar
  • Extract this .rar file
  • I got folder hierarchy as below











This folder hierarchy was made by extracting the rar file. Here you could see the media folder selected. Here you can find all the images in the word document. Thats it.

This trick also works for open office files.

About Me

My photo
Delhi, India
Fun, music, travel and nature loving, always smiling, computer addict!!