You are here: Hello » blog

Reliable way to get date in batch scripting

It's been long time since my last post, but I'm here, and watching :-)

Lately, I've got assignment to create MySQL backup script. It must be automatically scheduled by MS Windows Task Scheduler. As it is automatic, script should create new backup name each time. What is the best way to name backups? Probably to include date of backup.
And here my problems begins. If you grab date file_%date%.bak you may end up in various ways:

  • File can be created and named as you've expected;
  • Back up file does not appear (because of illegal characters used as date separator);
  • Backup file named somehow strangely.

I've tried all various ways to create file names as I wanted to by splitting date into Year, Mont and Day. But when it comes to locale- date can be in imperial style: YYYY/DD/MM
I want universal script to work on all locales or formats, so tried to catch date separator to guess format. This kind of tinkering complicated my script till unusable… And suddenly I step over WMI1) once again. This instrument is life saver. For real!! I have found Win32_OperatingSystem class in root\CIMV2 namespace. And you know what? It has exactly what I need. I just needed to query LocalDateTime property to get Date and time. This property hold my valuables in this format:

YearMonthDayHourMinuteSecond.Microsecond+Timezone
20130625094846.381000+180

This format is independent from locale or whatever else factors, it's allways the same.
Now I see my road bright and clear- I must use WMI to get my date and split it into Year, Mont and Day. This could be done quite simply in batch scripting file:

@ECHO OFF
for /f %%a in ('wmic os get LocalDateTime ^| findstr ^[0-9]') do (set ts=%%a)
ECHO %ts:~0,8%-%ts:~8,4%

This way I get 20130625-0948

So just script your filename as following and you are ready to go

SET filename = %ts:~0,8%.bak
2014/02/04 20:18 · 1 Comment

Anti-Spam Security

I hate spam, as everyone do. Since my website was quite vulnerable by spam bots- I had to implement some kind of security. From now on every unregistered user must enter capcha text, visible right after comment form. I don't mean to raise any difficulties for my visitors, but this type of security is essential.

2014/02/04 20:18 · 0 Comments

Obstacles and traps of JQuery

Celebration of Christmas and New Year have ended. Its time to back to work on projects.
Did some progress on Spot-In's server backend. Begun to update front end. I would like to allow user to delete his own report within few minutes after posting. It's quite ordinal in mobile UI2) that taphold3) event brings additional menu for touched item. I would like to use it to delete record.
Everything looks good till you try. Attached tap and taphold events for items and problems flow out:

  • If you taphold, tap event is executed
  • If you try to scroll down- taphold event is executed. As mentioned is previous problem, taphold is followed with tap.

Well, I could deal with tap and taphold problem if where would be no need to scroll down. This ListViews requirement was my traps. Searched whole web. I've tried various hakish ways of achieving what is needed and each time I've banged head into wall.

Finally, after a week I've found one simple and interesting solution, that really works. Swipe (scroll), taphold work perfectly. Solution is quite simple: taphold threshold and swipe duration threshold must differentiate at least 1ms(millisecond). And these thresholds mus be set before loading JQuery mobile library. Script should look like so:

<script type="text/javascript" charset="utf-8" src="jquery.min.js"></script>
<script type="text/javascript">
    $(document).bind("mobileinit", function () {
        $.event.special.tap.tapholdThreshold = 1000,
        $.event.special.swipe.durationThreshold = 999;
    });
</script>
<script type="text/javascript" charset="utf-8" src="jquery.mobile.min.js"></script>

One problem solved, but one left: how to prevent tap after taphold. I have tried everything what I came up with: various settings, hakish event handling and so on. This bug is registered in official jQuery bug tracked. Resolution- “wont fix” 8-o
And suddenly idea strike my head: unbind tap event on taphold and rebind it later. Little bit lame, but ir works :)

$("#object").on('taphold', function(e){
	$(this).off("click");
	//do whatever is needed
	setTimeout(function(){		//after 3 seconds return click event, as it was removed
		$(this).on("click", function(){
			// TAP event processing
		})
	},3000);
})

Looks like these two snippets let scroll, taphold and tap events to behave friendly without teasing each other :-)
Now I can continue to work on next version of spot-in for android.

P.S. I've found a remote Mac service. But about this later, till I be able to test it.

2014/02/04 20:18 · 0 Comments

iOS development

Apple probably is out of their mind?!

I'm looking for a way to develop iOS apps. My initial research gave me strange stare into monitor, then I found these “apple gems”. I have to pay 99$4) to be able to develop apps (even for myself), and to be able to release my apps- I must own MAC. Appple WTF?!

If I will not find working alternative on windows/linux- I'm not going to burn such a money. And my antipathy for apple is growing stronger and stronger.

2014/02/04 20:18 · 0 Comments

Spot-In project finished

I've just finished my second mobile application, named after Spot-In. Created using Apache Cordova5). It was quite a challenging job: I had to Create:

  • UI6),
  • Database structure,
  • Server side software,
  • Communication protocol
  • Glue everything into one working software package

I've had to deal with some Android 2.1-2.3 gliches like fixed position of footer bar (in this case footer is my menu) not on the bottom of the page if you scroll down the page. Some peoples used iScroll plugin for JQuery, but i've found even better and realy simple work-a-round. Look for this hack in tutorial section. Also it was a good practice of SQL and JQuery.

<< Newer entries | Older entries >>

1) Windows Management Instrument
2) , 6) user interface
3) click and hold for second
4) 265 Lt
5) aka PhoneGap
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported

Hey.lt - Nemokamas lankytojų skaitliukas XHTML