Monday, August 18, 2008
Facebook programming with ASP3
Posted by
RamiX
at
11:58 AM
6
comments
Labels: api, asp, facebook, functions, social networks, source codes
Sunday, February 10, 2008
Url Encode function. Encode a string according to W3C standards
this is a function that turns all the chars in a string to the W3C Standards. /**
* Encode a string according to W3C standards.
*
*/
public static String urlEncoder(String s) {
if (s == null)
return s;
StringBuffer sb = new StringBuffer(s.length() * 3);
try {
char c;
for (int i = 0; i < s.length(); i++) {
c = s.charAt(i);
if (c == '&') {
sb.append("&");
} else if (c == ' ') {
sb.append('+');
} else if (
(c >= ',' && c <= ';')
(c >= 'A' && c <= 'Z')
(c >= 'a' && c <= 'z')
c == '_'
c == '?') {
sb.append(c);
} else {
sb.append('%');
if (c > 15) { // is it a non-control char, ie. >x0F so 2 chars
sb.append(Integer.toHexString((int)c)); // just add % and the string
} else {
sb.append("0" + Integer.toHexString((int)c));
// otherwise need to add a leading 0
}
}
}
} catch (Exception ex) {
return (null);
}
return (sb.toString());
} source of this function : http://forum.java.sun.com/thread.jspa?threadID=594204&messageID=3596899
Posted by
RamiX
at
11:30 AM
1 comments
Labels: functions, java, source codes, url, W3C
Monday, January 28, 2008
Replace relative links to absolute base links in HTML - Java
this is a function that can add a base url to all urls in an html page, this code was translated from this vb function displayed here :http://www.motobit.com/tips/detpg_replace-relative-links/
special thanks to the original coder...
the function (java) was tested and run successfully!
public static String ReplaceLinksToBase(String HTML, String baseURL)
// replaces all links in an html to base url
// By Ramik, 28/1/2008
{
HTML = ReplaceTagToBase(HTML, "a", "href", baseURL);
// replace <img src=...> links
HTML = ReplaceTagToBase(HTML, "img", "src", baseURL);
HTML = ReplaceTagToBase(HTML, "link", "href", baseURL);
return HTML;
}
public static String ReplaceTagToBase (String HTML, String TagName, String ValueName, String BaseURL)
// replace a specific tag url to base Url
//By Ramik, 28/01/2008
{
int pos1, pos2;
String p1, p2, html;
html= HTML;
//Find the tag In HTML.
String temp = "<"+TagName ;
pos1 = HTML.indexOf(temp);
while (pos1>0)
{
//The tag was found. Find closing > of the tag.
pos2 = HTML.indexOf(">",pos1+TagName.length());
if (pos2>-1)
{
//separate tag text from HTML
String tag, tag1;
tag = HTML.substring(pos1, pos2);
//rewrite realative URL links In the one tag.
tag1 = ReplaceParamToBase(tag, ValueName, BaseURL);
//The tag was changed - relative links found.
if (!tag1.equals(tag)) //there is some change In the tag.
{
//get parts before And after the tag
p1 = HTML.substring(0,pos1);
p2 = HTML.substring(pos2,HTML.length());
//Compute new POs2 position
pos2 = pos2 + tag1.length() - tag.length() ;
//replace old tag with relative links with the new version
html = p1 + tag1 + p2 ;
}
}
if (pos2>0)
pos1 = HTML.indexOf("<"+TagName,pos2+1);
else
pos1 = 0 ;
}
return html;
}
public static String ReplaceParamToBase( String Tag, String ValueName,String BaseURL)
{
String p1, p2 , c1, URL, tag=Tag;
int pos1, pos2, lenVal ;
lenVal = ValueName.length() ;
//find position of the tag value
pos1 = Tag.indexOf(ValueName+"=");
if (pos1>-1)
{
//get a first char after =
c1 = Tag.substring(pos1+lenVal+1,pos1+lenVal+2);
if (c1.equals("\""))
{
pos1 = pos1+lenVal+1 ;
pos2 = Tag.indexOf("\"",pos1+1);
}
else if (c1.equals("'"))
{
pos1 = pos1+lenVal+1;
pos2 = Tag.indexOf("'",pos1+1);
}
else//the value ends with Space
{
pos1 = pos1+lenVal;
pos2 = Tag.indexOf(" ",pos1);
if (pos2==-1)
pos2 = Tag.length();
}
p1 = Tag.substring(0,pos1+1);
p2 = Tag.substring(pos2,Tag.length());
URL = Tag.substring(pos1+1,pos2);
//is the value relative URL?
if (URL.indexOf("://")==-1 && URL.indexOf("mailto:")==-1)
{
//make the new absolute URL
if (BaseURL.charAt(BaseURL.length()-1)!='/' && BaseURL.charAt(BaseURL.length()-1)!='\\' )
{
BaseURL=BaseURL+'/';
}
URL = BaseURL+URL ;
tag = p1+URL+p2;
}
}
return tag;
}
public static String replaceAllTags (String HTML, String TagName, String ValueName, String BaseURL)
//Replace all tags in html to base url
// by ramik 30/1/2008
{
String html = HTML , allHtml="";
int pos1=0, pos2 = HTML.indexOf(">");
if (pos2>-1)
pos2++;
while (pos2>-1)
{
html = HTML.substring(pos1,pos2);
allHtml = allHtml + ReplaceTagToBase(html,TagName, ValueName, BaseURL);
pos1=pos2;
pos2=HTML.indexOf(">",pos2);
if (pos2>-1)
pos2++;
}
allHtml = allHtml + HTML.substring(pos1);
return allHtml;
}
Discuss this Post
Posted by
RamiX
at
4:12 PM
1 comments
Wednesday, July 04, 2007
sql query for getting your users email servers
this is a query that get you a list of the servers of the users emails that they registered with, for example if you have 100 people that has a hotmail account and 200 users with gmail you will get this table:
count server
-----------------
100 hotmail
200 gmail
...
here is the query:
select * from
(SELECT Count(users.UserID) AS Count, right(users.Useremail,len(users.Useremail)-instr(users.Useremail,'@')) as server
FROM users
where users.useremail <> ''
GROUP BY right(users.Useremail,len(users.Useremail)-instr(users.Useremail,'@')))
order by count
Posted by
RamiX
at
9:16 AM
0
comments
Labels: database, db, queries, source codes, sql, sql server, sql server 2000, sql server 2005 express
Monday, July 02, 2007
Selection.Find crash
you wrote an application that works with Word object?
the application crashes in the middle of the run, after the debug you find that it crashes on this line:
WordObj.Selection.Find
well, it's not your fault, it's a microsoft bug. now, how you resolve it??
it's a tricky way,
what you should do is late binding
u should dim your word object as an General object and create it manualy, not by "new word"
here is a usefull code:
...
Dim wrdDoc As Object ' setting the word object as a general object
Dim IsWordRunning As Boolean
IsWordRunning = ApplicationIsRunning("Word.Application")
If IsWordRunning = True Then ' do
Set wrdApp = GetObject(, "Word.Application")
Else
Set wrdApp = CreateObject("Word.Application")
End If
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open(filename)
...
and here is the applicationisrunning function:Function ApplicationIsRunning(ApplicationClassName As String) As Boolean
' returns True if the application is running
' example: If Not ApplicationIsRunning("Outlook.Application") Then Exit Sub
Dim AnyApp As Object
On Error Resume Next
Set AnyApp = GetObject(, ApplicationClassName)
ApplicationIsRunning = Not AnyApp Is Nothing
Set AnyApp = Nothing
On Error GoTo 0
End Function
Posted by
RamiX
at
1:55 PM
0
comments
Labels: office, source codes, vb, vb.net, vb6, visual basic, visual studio, word
Tuesday, January 16, 2007
How to recognize google visit
do you want to know if this visit is a google visit??
here is a simple asp code to do that:
< % robot=request.ServerVariables("HTTP_USER_AGENT") if (Instr(robot,"Googlebot")<>0) then
...
end if
% >
and this is how to do it with php script
< ? define("SYSTEM_FROM_NAME","Your name"); define("SYSTEM_FROM_EMAIL","Your email"); //---this script will send email to webmaster when google visit your pages. if(isset($_SERVER['HTTP_USER_AGENT']) && eregi("googlebot",$_SERVER['HTTP_USER_AGENT'])) { if ($QUERY_STRING != "") { $url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].'?'.$QUERY_STRING; } else { $url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']; } $today = date("F j, Y, g:i a"); $headers = "From: ".SYSTEM_FROM_NAME." <".SYSTEM_FROM_EMAIL.">";
$message="";
$message.="Googlebot is crawling your site:\n";
$message.="Page: $url\n";
$message.="Date: $today \n";
$message.="IP: ".$_SERVER['REMOTE_ADDR']." \n";
mail(SYSTEM_FROM_EMAIL, "googlebot crawle - $url", "$message",$headers);}
? >
Posted by
RamiX
at
10:02 AM
0
comments
Labels: asp, google, php, scripts, Search engine, searchengines, seo, source codes
Wednesday, November 29, 2006
connecting btrieve database with vb6
you have an old version of btrieve and you want to read data from it?? well, you'r luck if you read this message in the beginning of your search... i lost 3 days of intensive searching.. and finaly found it. and here i share it with you...
well, open vb program and bla bla bla ...
now you should define some consts for easy work:
i suggest you to create a separate modul for this code (that what i did)
DefInt A-Z
Global Const BOPEN = 0
Global Const BCLOSE = 1
Global Const BINSERT = 2
Global Const BUPDATE = 3
Global Const BDELETE = 4
Global Const BGETEQUAL = 5
Global Const BGETNEXT = 6
Global Const BGETGREATEROREQUAL = 9
Global Const BGETFIRST = 12
Global Const BCREATE = 14
Global Const BSTAT = 15
Global Const BSTOP = 25
Global Const BVERSION = 26
Global Const BRESET = 28
Global Const KEY_BUF_LEN = 255
Rem Key FlagsGlobal Const DUP = 1
Global Const MODIFIABLE = 2
Global Const BIN = 4
Global Const NUL = 8
Global Const SEGMENT = 16
Global Const SEQ = 32
Global Const DEC = 64
Global Const SUP = 128
Rem Key Types
Global Const EXTTYPE = 256
Global Const MANUAL = 512
Global Const BSTRING = 0
Global Const BINTEGER = 1
Global Const BFLOAT = 2
Global Const BDATE = 3
Global Const BTIME = 4
Global Const BDECIMAL = 5
Global Const BNUMERIC = 8
Global Const BZSTRING = 11
Global Const BAUTOINC = 15
' now declare the function BTRCALL with do all the I\O with the database
Private Declare Function BTRCALL Lib "wbtrv32.dll" (ByVal OP, ByVal Pb$, Db As Any, DL As Long, Kb As Any, ByVal Kl, ByVal Kn) As Integer
' define some data types for working with the database files
Type typ_byte4 f1(1 To 4) As ByteEnd TypeRem ***************************************************************************
Rem Btrieve Structures
Type KeySpec
KeyPos As Integer
KeyLen As Integer
KeyFlags As Integer
KeyTot As typ_byte4
KeyType As String * 1
Reserved As String * 5
End Type
Type FileSpec
RecLen As Integer
PageSize As Integer
IndxCnt As Integer
NotUsed As String * 4
FileFlags As Integer
Reserved As String * 2
Allocation As Integer
KeyBuf(0 To 1) As KeySpec
End Type
Type StatFileSpecs
RecLen As Integer
PageSize As Integer
IndexTot As Integer
RecTot As typ_byte4
FileFlags As Integer
Reserved As String * 2
UnusedPages As Integer
KeyBuf(0 To 1) As KeySpec
End Type
Type RecordBuffer
' here you should define the structure of the file that you are reading.. in this example i have 3 'fields, one is an id (int) description and another float type
'change this to your data structure
profID As Integer
profDesc As String * 28
profPrice As Double
End Type
Type VersionBuf
Major As Integer
Minor As Integer
Engine As String * 1
End Type
Type typ_PosBlk
f1(1 To 128) As Byte
End Type
' defining variables with the types we created
Global FileBuf As FileSpec
Global DataBuf As RecordBuffer
Global StatFileBuffer As StatFileSpecs
Global BufLen As Long
Global DBLen As Integer
Rem*******Added to Open multiple files
Public iMaxRuns As Integer
Public bFilesCreated As Boolean
Sub PrintLB(Item As String)
' function for printing data on screen
Dim fTxtFileName As String
BtrFrm32.List1.AddItem Item
Rem Added to write info to file
fTxtFileName = App.Path & "\" & App.EXEName & ".log"
Open fTxtFileName For Append As #1
Print #1, Item Close #1
Rem *************
End Sub
sub readDate()
PrintLB ("Btrieve Sample Test Started")
PrintLB ("")
Rem Local variables needed for conversion from byte to long.
Dim loc_RecTot As Long
Dim h_field1 As String
Dim h_field2 As String
Dim h_field3 As String
Dim h_field4 As String
Dim h_total As String
'Rem **************************
FileName$ = "XFACE.BTR"
PosBlk$ = Space$(128)KeyBuffer$ = Space$(KEY_BUF_LEN)
RemRem ***************** Btrieve Create *********************Rem
Rem ************* SET UP FILE SPECS
FileBuf.RecLen = 34
FileBuf.PageSize = 1024
FileBuf.IndxCnt = 2
FileBuf.FileFlags = 0
''Rem ************* SET UP KEY SPECS
FileBuf.KeyBuf(0).KeyPos = 1
FileBuf.KeyBuf(0).KeyLen = 8
FileBuf.KeyBuf(0).KeyFlags = EXTTYPE + MODIFIABLE
FileBuf.KeyBuf(0).KeyType = Chr$(BFLOAT)
FileBuf.KeyBuf(1).KeyPos = 9
FileBuf.KeyBuf(1).KeyLen = 26
FileBuf.KeyBuf(1).KeyFlags = EXTTYPE + MODIFIABLE + DUP
FileBuf.KeyBuf(1).KeyType = Chr$(BSTRING)
'Open File
KeyBufLen = KEY_BUF_LEN
KeyBuffer$ = txtFileName.txt
BufLen = Len(DataBuf)KeyNum = 0
Status = BTRCALL(BOPEN, PosBlk$, DataBuf, BufLen, ByVal KeyBuffer$, KeyBufLen, KeyNum)
If Status <> 0 Then
Msg$ = "Error Opening file! " + Str$(Status)
PrintLB (Msg$)
GoTo Fini
Else
Msg$ = "File Opened Successfully!" PrintLB (Msg$)
End If
BufLen = Len(DataBuf)
KeyBuffer$ = Space$(255)
KeyBufLen = KEY_BUF_LEN
'Status = BTRCALL(BGETFIRST, PosBlk$, DataBuf, BufLen, ByVal KeyBuffer$, KeyBufLen, 0)
If Status <> 0 Then
Msg$ = "Error on BGETFIRST. " + Str$(Status)
PrintLB (Msg$)
Else
Msg$ = "BGETFIRST okay for : " + DataBuf.profDesc PrintLB (Msg$)
End If
'Get Next Record
BufLen = Len(DataBuf)KeyBuffer$ = Space$(KEY_BUF_LEN)
KeyBufLen = KEY_BUF_LEN
Status = BTRCALL(BGETNEXT, PosBlk$, DataBuf, BufLen, ByVal KeyBuffer$, KeyBufLen, 0)
If Status <> 0 Then
Msg$ = "Error on BGETNEXT. " + Str$(Status)
PrintLB (Msg$)
Else
Msg$ = "BGETFIRST okay for : " + DataBuf.profDesc
PrintLB (Msg$)
End If
end sub
Posted by
RamiX
at
1:52 PM
0
comments
Labels: btrieve, database, db connection, pervasive, source codes, sql
Thursday, November 23, 2006
Using Notify Icon Object
notifyIcon1.Icon = new System.Drawing.Icon(@"c:\1.ico");
notifyIcon1.Visible = true;
notifyIcon1.Text = "Test Notify Icon Demo";
notifyIcon1.BalloonTipTitle = "ByRamiX Product";
notifyIcon1.BalloonTipText = "This Product was programmed ByRamiX";
notifyIcon1.ShowBalloonTip(5000);
Posted by
RamiX
at
10:29 AM
0
comments
Labels: .net, c#, source codes, windows programming
Tuesday, October 10, 2006
connecting a database with c# / asp.net
this is the code of database connection and sql executing functions
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
///
/// data base class
///
public class db
{
OleDbConnection gDbConn;
OleDbCommand gDbCmd;
public string error;
public db(string connStr)
{
try
{
gDbCmd = new OleDbCommand();
gDbConn = new OleDbConnection();
gDbConn.ConnectionString = connStr;
error="class built successfully";
}
catch (Exception e)
{
error = "[class constructor] building class faild, error in connecting database error discribe: "+e.Message ;
}
}
public OleDbDataReader executeSQL(String sql)
{
try
{
OleDbDataReader rs ;
gDbConn.Open();
gDbCmd.Connection = gDbConn;
gDbCmd.CommandText = sql;
if (sql.Contains("select") )
rs = gDbCmd.ExecuteReader();
else
{
gDbCmd.ExecuteNonQuery();
rs = null;
}
error = "executeSQL executed successfully";
return rs;
}
catch(Exception e)
{
error = "[execute sql] failed to execute sql statement error discribe:" + e.Message
return null;
}
}
}
an example of using this class here: http://byramix.blogspot.com/2006/10/using-data-base-class.html
Posted by
RamiX
at
12:24 AM
0
comments
Labels: ado, asp.net, c#, database, db connection, source codes, sql server
Friday, July 14, 2006
SELECT random records from a database
asp script:
randomize
sql="select max (ID) as maxid from table"rs.open sql,cn
max=rs("maxid")
rs.close
for i=0 to 100
rndNum=int(rnd()*max)+1
idstr=idstr&rndNum&","
next
idstr=idstr+"0"
sql="select top 25 ID, * from table where ID in ("+idstr+")"
rs.open sql,cn
<% randomize sql="select max (ID) as maxid from table" rs.open sql,cn max=rs("maxid") rs.close for i=0 to 100 rndNum=int(rnd()*max)+1 idstr=idstr&rndNum&"," next idstr=idstr+"0" sql="select top 25 ID, * from table where ID in ("+idstr+")" rs.open sql,cn %>
Posted by
RamiX
at
7:43 PM
0
comments
Labels: asp, asp.net, php, source codes, sql, windows programming

