This post is made to test twitterfeed.
Hopefully it can revived this blog also
This post is made to test twitterfeed.
Hopefully it can revived this blog also
It’s quite a time since I post my last tutorials. Coming up next will be one of these two:
1. Ms. SharePoint 2007
2. Fuzzy Logic, Concept and Implementation
The first one is related to my current work in my office and the second one is purely hobby. Which one goes first?
Well…. Work or Hobby Guys?
I figure out this code when I try to run the .dtsx package from C#.
Quite a prospect, I guess. The .dtsx package (Sql Server Integration Service) itself has open many possibilites to do some ETL and Data Warehousing. I won’t cover the ETL Tutorial with SSIS in this post though, I’m still learning on it.
I just want to share the code I made to run simple .dtsx package. When I try searching the tutorial in http://msdn2.microsoft.com/en-us/library/ms136090.aspx I got some errors when I compiled it, therefore I made some slight changes to make it work:
Here is my code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
namespace MyConsole
{
class Program
{
static void Main(string[] args)
{
string pkgLocation;
Package pkg;
Application app;
DTSExecResult pkgResults;
pkgLocation =
@”C:\Documents and Settings\User\My Documents\Visual Studio 2005\Projects\TheIntegration\TheIntegration\Package.dtsx”;
app = new Application();
pkg = (Package)app.LoadPackage(pkgLocation, true, null);
pkgResults = pkg.Execute();
Console.WriteLine(pkgResults.ToString());
Console.ReadKey();
}
}
}
Please note that the location string is the location of your .dtsx file. One more thing, don’t forget to add Microsoft.SQLServer.DTSRuntimeWrap.dll as reference.
Hope it help!
Below, is a code for encoding password with RC4 Algorithm with PHP. I got this code from PHP Tricks, however when I try the code, it return a “division by zero” error, so I make some slight modification to it. Enjoy!
<?php
/*
Security Code.
*/
$SEC_CODE = ‘kdjfhgO(*&lojidsgoYOIM’;
/*
First Encoding Step,
High Level Encoding
Using RC4 Alogrithem
*/
function RC4($data,$pwd) {
$pwd = $keyfile;
$pwd_length = strlen($pwd);
if ($pwd_length > 0){ // add by anthonysteven
for ($i = 0; $i < 255; $i++) {
$key[$i] = ord(substr($pwd, ($i % $pwd_length)+1, 1));
$counter[$i] = $i;
}
}// add by anthonysteven
for ($i = 0; $i < 255; $i++) {
$x = ($x + $counter[$i] + $key[$i]) % 256;
$temp_swap = $counter[$i];
$counter[$i] = $counter[$x];
$counter[$x] = $temp_swap;
}
for ($i = 0; $i < strlen($data); $i++) {
$a = ($a + 1) % 256;
$j = ($j + $counter[$a]) % 256;
$temp = $counter[$a];
$counter[$a] = $counter[$j];
$counter[$j] = $temp;
$k = $counter[(($counter[$a] + $counter[$j]) % 256)];
$Zcipher = ord(substr($data, $i, 1)) ^ $k;
$Zcrypt .= chr($Zcipher);
}
return $Zcrypt;
}
/*
Hex to Binary Converter
Used to get the password
after encoding
*/
function hex2bin($hexdata) {
for ($i=0;$i<strlen($hexdata);$i+=2) {
$bindata.=chr(hexdec(substr($hexdata,$i,2)));
}
return $bindata;
}
/*
Encoding The Info
*/
// Add by anthonysteven
echo “
<form method = ‘post’ action=”.$_Server["PHP_SELF"].”>
Enter Password:
<input type=’text’ name=’pass’>
<input type=’submit’ value=’submit’>
</form>”;
// Add by anthonysteven
$my_password = $_POST['pass'];
$new_password = bin2hex(RC4($my_password,SEC_CODE));
echo “New Password (After RC4) = “$new_password;
echo “<BR>”;
/*
Decoding The Info
*/
$my_password = RC4(hex2bin($new_password),$SEC_CODE);
echo “Old Password = “$my_password;
?>
This is an english version of the tutorial I posted here (in bahasa Indonesia).
K-Means is a classic algorithm that are used for data mining or to be more specific partitional clustering type of data mining.
What did K-Means do?
Two things that we should keep in mind:
1. K-Means is an unsupervised learning algorithm. It means K-Means, after given some initial condition will “learn” by itself without any supervision or human intervention
2. K-Means is a partitional clustering algorithm. It divides data into a number of clusters given without giving any hierarchies. You won’t find tree in this algorithm, consider it luck
To ease my explaining and you understanding, let us head to the example.
For example, I have a data set S = {3,6,7,2,3,12} and I want to divide it into, say, two clusters using K-Means. This are the steps:
1. Centroid Initialization
Each cluster has a center value named centroid, now the first thing we will do is initialize the value of the centroids. How? The first way is to simply make a random choice on the data set. The second way (and the better way, is to sort the data and choose the data that are located in a position that will divide the data set into some number of cluster given.
Now, we will try the second way, first we sort the data:
S` = {2,3,3,6,7,12}
Than we make the first data ‘2′ and the fourth data ‘4′ to be the initialized.
So, C1 (centroid 1) = 2, and C2 = 6.
2. Divide the data into the clusters.
How? Simply by comparing the data with the centroids (to achieve distance). Data goes to a cluster that has less distance.
S` = {2,3,3,6,7,12}
C1 = 2
C2 = 6
Clu1(Cluster 1) = {2,3,3}
Clu2(Cluster 2) = {6,7,12}
3. Update Centroid Value
Update Centroid Value by counting the means of the cluster.
C1` = 2+3+3/3 = 2.67
C2` = 6+7+12/3 = 8.33
4. Compare the new centroid value with the old ones
If the new and old on values the same or their distance is below minimum tolerance, it means the algorithm has reach a stable point, and it’s time to stop.
C1` – C1 = 0.67
C2` – C2 = 2.33
Because it is not stable, we go back to step 2 with the new centroid value.
5. (Step 2)
S` = {2,3,3,6,7,12}
C1′ = 2.67
C2′ = 8.33
Clu1(Cluster 1) = {2,3,3}
Clu2(Cluster 2) = {6,7,12}
6. (Step 3)
C1“ = 2+3+3/3 = 2.67
C2“ = 6+7+12/3 = 8.33
7. (Step 4)
C1“ – C1` = 0
C2“ – C2` = 0
The algorithm stable! so, now we get the result:
Clu1(Cluster 1) = {2,3,3}
Clu2(Cluster 2) = {6,7,12}
~hopeItHelp!
This blog is my online tutorial place where I will put my knowledge or others proven good knowledge about coding. I’m still learning though and I’m not a code-freak myself so I’m just trying to share and help.
Your responses for my tutorial will be a tremendous help.
niceDay!
Recent Comments