Tuesday, February 10, 2015

Minifying JS in Windows easily with Ajaxmin BATCH script

Minifying js and css file has been a standard practice to reduce the webpage size.
Various tools are created to tackle the problem, especially on Mac OS X that includes batch processing capabilities.

However, it is a pain to do so in Windows without installing 3rd party extension into IDE.

This motivate me to write a simple script that can batch processing the js and easy to use.

This is a batch script that minify js and css files using AjaxMin
The script will scan current folder and its sub folder.
It will save the minified file with .min.js or .min.css

This batch script required AjaxMin to run, install AjaxMin into its default folder
C:\Program Files (x86)\Microsoft\Microsoft Ajax Minifier

@ECHO off
set PATH="C:\Program Files (x86)\Microsoft\Microsoft Ajax Minifier\";%PATH%
setlocal enabledelayedexpansion
for /f %%f in ('dir /b /s^|findstr /r ".*\.js$ .*\.css$"') do (
set "N=%%f"
if "!N:.min%%~xf=!"=="!N!" (
@ajaxmin -clobber %%f -o %%~npf.min%%~xf
)
)
pause
save the script as .bat file
copy it to your /js folder and run it.

Feel free to copy and modify.

Tuesday, January 11, 2011

Fixing Windows Live Messenger

If you having Your Windows Live Messenger HANG/LAG for every 10 ~ 20 Second.
Here might be your solutions.

Go to Start -> Run

Type in services.msc and then Enter.

You will see a list of Services on your Windows

Scroll down to SSDP Discovery, stop the service and set the startup type to disable.
(There might be a popup window asking to stop the UPNP as well, click ok to stop the UPNP as well.)

Shutdown Messenger and restart your Windows.

Test your messenger, now it will not HANG or LAG for every few second anymore.

Go back to your services.msc

restore all the changes you had made.

Wednesday, December 29, 2010

Modifying Openkore to Enable KS

Today, out of curious, I open inside my openkore openkore/scr folder to see what happen inside.There is a limitation every openkore user known, the bot will not kill steal others.So I try to look inside the scr/AI/Attack.pm to see what I can do to overcome the limitation.

And very lucky, I saw this block

# Check for kill steal and mob-training while moving
if ((AI::is("move", "route") && $args->{attackID} && AI::inQueue("attack")
&& timeOut($args->{movingWhileAttackingTimeout}, 0.2))) {



See the comment, our solution is here !!!!
Scroll down a bit an I found these line


# Check for kill steal while moving
if ($monster && !Misc::checkMonsterCleanness($ID)) {
message T("Dropping target - you will not kill steal others\n");


So the condition check is the Misc::checkMonsterCleanness. I can change to

Misc::checkMonsterCleanness($ID);
if ($monster && 0) {
message T("Dropping target - you will not kill steal others\n");


So it will condition will never met. To prevent error, I will call the function Misc::checkMonsterCleanness before the condition check.

To play safe, I didn't do that, I find the source of Misc::checkMonsterCleanness.
The file is scr/Misc.pm

Then, a simple search of keyword clean and I got here

##
# boolean checkMonsterCleanness(Bytes ID)
# ID: the monster's ID.
# Requires: $ID is a valid monster ID.
#
# Checks whether a monster is "clean" (not being attacked by anyone).
sub checkMonsterCleanness {
return 1 if (!$config{attackAuto});
my $ID = $_[0];
return 1 if ($playersList->getByID($ID));
my $monster = $monstersList->getByID($ID);

# If party attacked monster, or if monster attacked/missed party
if ($monster->{dmgFromParty} > 0 || $monster->{dmgToParty} > 0 || $monster->{missedToParty} > 0) {
return 1;
}

if ($config{aggressiveAntiKS}) {
# Aggressive anti-KS mode, for people who are paranoid about not kill stealing.

# If we attacked the monster first, do not drop it, we are being KSed
return 1 if ($monster->{dmgFromYou} || $monster->{missedFromYou});

# If others attacked the monster then always drop it, wether it attacked us or not!
return 0 if (($monster->{dmgFromPlayer} && %{$monster->{dmgFromPlayer}})
|| ($monster->{missedFromPlayer} && %{$monster->{missedFromPlayer}})
|| (($monster->{castOnByPlayer}) && %{$monster->{castOnByPlayer}})
|| (($monster->{castOnToPlayer}) && %{$monster->{castOnToPlayer}}));
}

# If monster attacked/missed you
return 1 if ($monster->{'dmgToYou'} || $monster->{'missedYou'});

# If we're in follow mode
if (defined(my $followIndex = AI::findAction("follow"))) {
my $following = AI::args($followIndex)->{following};
my $followID = AI::args($followIndex)->{ID};

if ($following) {
# And master attacked monster, or the monster attacked/missed master
if ($monster->{dmgToPlayer}{$followID} > 0
|| $monster->{missedToPlayer}{$followID} > 0
|| $monster->{dmgFromPlayer}{$followID} > 0) {
return 1;
}
}
}

if (objectInsideSpell($monster)) {
# Prohibit attacking this monster in the future
$monster->{dmgFromPlayer}{$char->{ID}} = 1;
return 0;
}

#check party casting on mob
my $allowed = 1;
if (scalar(keys %{$monster->{castOnByPlayer}}) > 0)
{
foreach (keys %{$monster->{castOnByPlayer}})
{
my $ID1=$_;
my $source = Actor::get($_);
unless ( existsInList($config{tankersList}, $source->{name}) ||
($char->{party} && %{$char->{party}} && $char->{party}{users}{$ID1} && %{$char->{party}{users}{$ID1}}))
{
$allowed = 0;
last;
}
}
}

# If monster hasn't been attacked by other players
if (scalar(keys %{$monster->{missedFromPlayer}}) == 0
&& scalar(keys %{$monster->{dmgFromPlayer}}) == 0
#&& scalar(keys %{$monster->{castOnByPlayer}}) == 0 #change to $allowed
&& $allowed

# and it hasn't attacked any other player
&& scalar(keys %{$monster->{missedToPlayer}}) == 0
&& scalar(keys %{$monster->{dmgToPlayer}}) == 0
&& scalar(keys %{$monster->{castOnToPlayer}}) == 0
) {
# The monster might be getting lured by another player.
# So we check whether it's walking towards any other player, but only
# if we haven't already attacked the monster.
if ($monster->{dmgFromYou} || $monster->{missedFromYou}) {
return 1;
} else {
return !objectIsMovingTowardsPlayer($monster);
}
}

# The monster didn't attack you.
# Other players attacked it, or it attacked other players.
if ($monster->{dmgFromYou} || $monster->{missedFromYou}) {
# If you have already attacked the monster before, then consider it clean
return 1;
}
# If you haven't attacked the monster yet, it's unclean.

return 0;
}


Then I make these changes

The comment said if the function return 1 show the the monster is clean and ok for attacking.

##
# boolean checkMonsterCleanness(Bytes ID)
# ID: the monster's ID.
# Requires: $ID is a valid monster ID.
#
# Checks whether a monster is "clean" (not being attacked by anyone).
sub checkMonsterCleanness {
return 1 if (!$config{attackAuto});
my $ID = $_[0];
return 1 if ($playersList->getByID($ID));
my $monster = $monstersList->getByID($ID);

# If party attacked monster, or if monster attacked/missed party
if ($monster->{dmgFromParty} > 0 || $monster->{dmgToParty} > 0 || $monster->{missedToParty} > 0) {
return 1;
}

if ($config{aggressiveAntiKS}) {
# Aggressive anti-KS mode, for people who are paranoid about not kill stealing.

# If we attacked the monster first, do not drop it, we are being KSed
return 1 if ($monster->{dmgFromYou} || $monster->{missedFromYou});

# If others attacked the monster then always drop it, wether it attacked us or not!
return 1 if (($monster->{dmgFromPlayer} && %{$monster->{dmgFromPlayer}})
|| ($monster->{missedFromPlayer} && %{$monster->{missedFromPlayer}})
|| (($monster->{castOnByPlayer}) && %{$monster->{castOnByPlayer}})
|| (($monster->{castOnToPlayer}) && %{$monster->{castOnToPlayer}}));
}

# If monster attacked/missed you
return 1 if ($monster->{'dmgToYou'} || $monster->{'missedYou'});

# If we're in follow mode
if (defined(my $followIndex = AI::findAction("follow"))) {
my $following = AI::args($followIndex)->{following};
my $followID = AI::args($followIndex)->{ID};

if ($following) {
# And master attacked monster, or the monster attacked/missed master
if ($monster->{dmgToPlayer}{$followID} > 0
|| $monster->{missedToPlayer}{$followID} > 0
|| $monster->{dmgFromPlayer}{$followID} > 0) {
return 1;
}
}
}

if (objectInsideSpell($monster)) {
# Prohibit attacking this monster in the future
$monster->{dmgFromPlayer}{$char->{ID}} = 1;
return
1
;
}

#check party casting on mob
my $allowed = 1;
if (scalar(keys %{$monster->{castOnByPlayer}}) > 0)
{
foreach (keys %{$monster->{castOnByPlayer}})
{
my $ID1=$_;
my $source = Actor::get($_);
unless ( existsInList($config{tankersList}, $source->{name}) ||
($char->{party} && %{$char->{party}} && $char->{party}{users}{$ID1} && %{$char->{party}{users}{$ID1}}))
{
$allowed = 0;
last;
}
}
}

# If monster hasn't been attacked by other players
if (scalar(keys %{$monster->{missedFromPlayer}}) == 0
&& scalar(keys %{$monster->{dmgFromPlayer}}) == 0
#&& scalar(keys %{$monster->{castOnByPlayer}}) == 0 #change to $allowed
&& $allowed

# and it hasn't attacked any other player
&& scalar(keys %{$monster->{missedToPlayer}}) == 0
&& scalar(keys %{$monster->{dmgToPlayer}}) == 0
&& scalar(keys %{$monster->{castOnToPlayer}}) == 0
) {
# The monster might be getting lured by another player.
# So we check whether it's walking towards any other player, but only
# if we haven't already attacked the monster.
if ($monster->{dmgFromYou} || $monster->{missedFromYou}) {
return 1;
} else {
objectIsMovingTowardsPlayer($monster);
return 1 ;

}
}

# The monster didn't attack you.
# Other players attacked it, or it attacked other players.
if ($monster->{dmgFromYou} || $monster->{missedFromYou}) {
# If you have already attacked the monster before, then consider it clean
return 1;
}
# If you haven't attacked the monster yet, it's unclean.

return 1;
}


I changed all the return 0 to return 1, so whatever happens, i didn't affect the whole process and always return 1.And the result is good, my bot work nicely and KS-ing people.

The above result is made by tried and error. One of the funny modify I made is the bot will ks and ONLY ks other player, it won't attack a standing monster unless the monster attacked by other player.

An easier solution will be changing

##
# boolean checkMonsterCleanness(Bytes ID)
# ID: the monster's ID.
# Requires: $ID is a valid monster ID.
#
# Checks whether a monster is "clean" (not being attacked by anyone).
sub checkMonsterCleanness {
return 1 if (!$config{attackAuto});

to

##
# boolean checkMonsterCleanness(Bytes ID)
# ID: the monster's ID.
# Requires: $ID is a valid monster ID.
#
# Checks whether a monster is "clean" (not being attacked by anyone).
sub checkMonsterCleanness {
return 1 if ($config{attackAuto});

*I didn't try this, modify at your own risk.*


Warning:
KS bot will piss off hand player, making your character banned from server.

Sunday, May 16, 2010

XOR Encryptor

I am trying how simple XOR works and try out some control.

.exe:http://www.mediafire.com/file/miymdntmyj2/XOR Encryption.exe

Source:http://www.mediafire.com/file/miymdntmyj2/XOR Encryption.exe

bug existed:
-character with even times of occurence will not be encryted, because of the System::String Replace function which replace all the character specified in the string.
#Possible solution,break into string array and XOR one string by one string.

Wednesday, May 12, 2010

Decimal Binary Convertor beta

After alot of reading, I manage to use the template in visual studio to create this little program.

exe: http://www.mediafire.com/file/4mmmmtz0nhm/Calculator.exe
source: http://www.mediafire.com/file/ggozddygomy/Calculator.rar

The code is written in the header file (what the?),with the help of an youtube video of making a calculator with visual c++.

Tuesday, May 11, 2010

The first step.

Yeah, finally cs1102c nightmare has ended. Instead of coding something funny to solve the funny questions, I want to start coding something usefull.

So, programming knowledge of cs1101c and cs1102c is not enough.There are many things I have to learn myself, first thing come into my mind is GUI.

I will start with something simple, Binary Decimal convertor.This will be usefull for my second year study as we need to learn binary.

And the achievement so far:
Microsoft Visual studio 2010 ultimate 74% downloaded.
Algorithm for decimal to binary finished.
Learning GUI 0%.

Things to do:
mastering visual c++.
Create a GUI.
Algorithm for binary to decimal(should be easy).

Possible improvement for the convertor,
Support basic calculation for the input form.
Become a universal convertor.