Showing posts with label Script. Show all posts
Showing posts with label Script. Show all posts

Tuesday, November 20, 2018

All Mighty Scripts



Resize Jpegs into 75% in PDF:

path C:\Program Files\gs\gs9.20\bin
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=small.pdf big.pdf
pause



------------------------

Resize Jpegs into 150% in PDF:

path C:\Program Files\gs\gs9.20\bin
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=small.pdf big.pdf
pause


------------------------
//Csharp is much better than python for web searching, data mining and big data

//-----------------------------------

//Only for Windows XP, 7, 8, 10

using System;
using System.Windows.Forms;
using System.Net;
using System.Diagnostics;
using System.Net.Mail;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;




public class MyForm : Form
{
  private Button btnDugme = new Button();

  public MyForm()
  {
    this.Text = "Big data blender";
    btnDugme.Text = "Start";
    btnDugme.Width = 100;
    btnDugme.Height = 40;
    btnDugme.Top = 10;
    btnDugme.Left = 10;
    btnDugme.Click += new EventHandler(btnDugme_Click);
    this.Controls.Add(btnDugme);
}

  private void btnDugme_Click(object o, EventArgs e)
  {
 
MessageBox.Show("Ide Mile lajkovachkom prugom... gyere Ide Meeley like-o-wach-kom prugom...");

           try

            {

 using (WebClient client = new WebClient())
{


    string htmlCode = client.DownloadString("https://www.google.rs");
    //MessageBox.Show(htmlCode);

        for (int i = 0; i < 1; i++)
        {
     //btnDugme.Text = i.ToString()+" %";
             htmlCode = client.DownloadString("https://www.google.rs");
             //htmlCode = client.DownloadString("http://www.bing.com");
if (htmlCode.Length > 2000)
{
htmlCode = htmlCode.Substring(0,2000);
}
     Console.WriteLine(htmlCode);
     Console.WriteLine(i);


Console.Write(" % ");
        }
Console.WriteLine("Ide Mile...");


}

            }

            catch (Exception ex)

            {
string a = ex.ToString();
                MessageBox.Show(ex.ToString());
                MessageBox.Show("No internet - Nema interneta !");

Console.WriteLine("Niste na internetu, konektujte se pa kliknite na dugme ponovo.");
Console.WriteLine("You are not connected to internet, please connect to internet and continue digging.");


            }

  }

  private static void Main()
  {
    Application.Run(new MyForm());
  }
}



----------------------------

MORE TIPS:

https://dictation.io/speech



https://www.google.com/intl/es/chrome/demos/speech.html


-----------------------------

CHECK THIS OUT:

https://software.intel.com/en-us/html5/hub/highlights



**







Interesantni Python primeri

https://www.pythonforbeginners.com/basics/list-comprehensions-in-python

https://www.programiz.com/python-programming/closure

https://www.w3schools.com/python/ref_func_map.asp

Game changer for Bots, Scalpers and used in Google Search Bots for retrieving search data from millions of websites for Googles Search Engine Data.
I use it for requesting all CSS, JavaScript and Images once I’ve retrieved the HTML file from a HTTP Request. Bots use it to grab HTML from set list of http or https website paths stored into Lists Arrays.
Yes it retrieves them all using Multi-Threads. They then process all these files to pull out data from SEO meta tags, header tags, site title and possibly the first few paragraphs of each websites main page.
  1. threads = [threading.Thread(target=fetch_url, args=(url,)) for url in cs]
  2. for thread in threads: ;thread.start()
  3. for thread in threads: ;thread.join()
It can be set to retrieve 100 to 200 websites html pages/files and download them all in the same amount of time as a single http request.
My test running “import time time.time()” . How fast is it? For a single website request to fetch all local CSS paths from the HTML Page is under 1.75 combined average time in seconds for Python.org main page with all of its CSS downloaded. Fast Enough for my Mosaic Browser.

Monday, September 24, 2018

Typed Files in Delphi & Lazarus

Simply put a file is a binary sequence of some type. In Delphi, there are three classes of filetyped, text, and untyped. Typed files are files that contain data of a particular type, such as Double, Integer or previously defined custom Record type. Text files contain readable ASCII characters. Untyped files are used when we want to impose the least possible structure on a file.

Typed Files

While text files consist of lines terminated with a CR/LF (#13#10) combination, typed files consist of data taken from a particular type of data structure.
For example, the following declaration creates a record type called TMember and an array of TMember record variables.
 type
  TMember = record
    Name : string[50];
    eMail : string[30];
    Posts : LongInt;
  end;
 var Members : array[1..50] of TMember; 
Before we can write the information to the disk we have to declare a variable of a file type. The following line of code declares an F file variable.
 var F : file of TMember; 
Note: To create a typed file in Delphi, we use the following syntax:
var SomeTypedFile : file of SomeType
The base type (SomeType) for a file can be a scalar type (like Double), an array type or record type. It should not be long string, dynamic array, class, object or a pointer.
In order to start working with files from Delphi, we have to link a file on a disk to a file variable in our program. To create this link we must use AssignFile procedure in order to associate a file on a disk with a file variable.
 AssignFile(F, 'Members.dat') 
Once the association with an external file is established, the file variable F must be 'opened' to prepare it for reading and/or writing. We call Reset procedure to open an existing file or Rewrite to create a new file. When a program completes processing a file, the file must be closed using the CloseFile procedure. After a file is closed, its associated external file is updated. The file variable can then be associated with another external file.
In general, we should always use exception handling; many errors may arise when working with files. For example: if we call CloseFile for a file that is already closed Delphi reports an I/O error. On the other hand, if we try to close a file but have not yet called AssignFile, the results are unpredictable.

Write to a File

Suppose we have filled an array of Delphi members with their names, e-mails, and number of posts and we want to store this information in a file on the disk. The following piece of code will do the work:
 var
  F : file of TMember;
  i : integer;
begin
 AssignFile(F,'members.dat') ;
 Rewrite(F) ;
 try
  for j:= 1 to 50 do
   Write (F, Members[j]) ;
 finally
  CloseFile(F) ;
 end;
end; 

Read from a File

In order to retrieve all the information from the 'members.dat' file we would use the following code:
 var
  Member: TMember
  F : file of TMember;
begin
 AssignFile(F,'members.dat') ;
 Reset(F) ;
 try
  while not Eof(F) do begin
   Read (F, Member) ;
   {DoSomethingWithMember;}
  end;
 finally
  CloseFile(F) ;
 end;
end; 
Note: Eof is the EndOfFile checking function. We use this function to make sure that we are not trying to read beyond the end of the file (beyond the last stored record).

Seeking and Positioning

Files are normally accessed sequentially. When a file is read using the standard procedure Read or written using the standard procedure Write, the current file position moves to the next numerically ordered file component (next record). Typed files can also be accessed randomly through the standard procedure Seek, which moves the current file position to a specified component. The FilePos and FileSizefunctions can be used to determine the current file position and the current file size.
 {go back to the beginning - the first record}
Seek(F, 0) ;
{go to the 5-th record}
Seek(F, 5) ;
{Jump to the end - "after" the last record}
Seek(F, FileSize(F)) ; 

Change and Update

You've just learned how to write and read the entire array of members, but what if all you want to do is to seek to the 10th member and change the e-mail? The next procedure does exactly that:
 procedure ChangeEMail(const RecN : integer; const NewEMail : string) ;
var DummyMember : TMember;
begin
 {assign, open, exception handling block}
 Seek(F, RecN) ;
 Read(F, DummyMember) ;
 DummyMember.Email := NewEMail;
 {read moves to the next record, we have to
 go back to the original record, then write}
 Seek(F, RecN) ;
 Write(F, DummyMember) ;
 {close file}
end;

Completing the Task


That's it -- now you have all you need to accomplish your task. You can write members' information to the disk, you can read it back and you can even change some of the data (e-mail, for example) in the "middle" of the file.


ORIGINAL ARTICLE:

https://www.thoughtco.com/create-database-delphis-file-typed-files-1058003






NEMA ODMORA DOK TRAJE OBNOVA ---->>>>>

IDEMO DALJE ------------>>>>>

Friday, April 28, 2017

Tuesday, April 25, 2017

VBS tut

set shellobj = CreateObject("WScript.Shell")
shellobj.run "cmd"
wscript.sleep 100
shellobj.sendkeys "shutdown"
wscript.sleep 20
Shellobj.sendkeys " /s"
wscript.sleep 20
shellobj.sendkeys [ENTER]

------------------


x=msgbox("Would you like to open the Windows folder?" ,4, "Question:")

If x = vbNo Then Wscript.Quit(0)

If x = VbYes Then

Set WshShell = CreateObject("WScript.Shell")

X = WshShell.run("cmd /c explorer.exe ""C:\Windows""",0, true)

End If

------------------------

strMB = inputbox("Please enter your message here:")

Set WshShell = CreateObject("WScript.Shell")

WshShell.run "cmd /c @echo msgbox " & """" & strMB & """" & ",4096,""VBS2CMD2VBS:"">C:\Message.vbs",0, true

WshShell.run "C:\windows\system32\wscript.exe C:\Message.vbs",0, false

Wscript.Quit(0)


-----------------------------

strMB = inputbox("Please enter your message here:")

msgbox strMB, 4096, "Message"

------------------------


(A)

x=msgbox("Would you like to continue?" ,4, "Question:")

If x = vbNo Then MsgBox "You selected 'No'", 4096, "No:"

If x = VbYes Then MsgBox "You selected 'Yes'", 4096, "Yes:"

(B)

x=msgbox("Would you like to continue?" ,4, "Question:")

If x = vbNo Then

MsgBox "You selected 'No'", 4096, "No:"

Wscript.Quit(0)

End If

If x = VbYes Then

MsgBox "You selected 'Yes'", 4096, "Yes:"

Wscript.Quit(0)

End If

(C)

x=msgbox("Would you like to continue?" ,4, "Question:")

If x = vbNo Then

MsgBox "You selected 'No'", 4096, "No:"

Else

MsgBox "You selected 'Yes'", 4096, "Yes:"

End If

Wscript.Quit(0)


-------------------------


x=msgbox("Would you like to continue?" & VbCrLf & "If you select No, you will see NO" & VbCrLf & VbCrLf & "If you select Yes, you will see YES",4, "Question:")

If x = vbNo Then

MsgBox "NO", 4096, "No:"

Else

MsgBox "YES", 4096, "Yes:"

End If

--------------------------------------


Set WshShell = CreateObject("WScript.Shell")

x = WshShell.Popup("Would you like to continue?",5,"Title:",4)

If x = vbNo Then Wscript.Quit(0)

If x = VbYes Then

'Your script goes here

msgbox "you selected YES!", 4096, "Yes"

End If


--------------------------------------------



'************************************************
' File:    Input.vbs (WSH sample in VBScript) 
' Author:  (c) G. Born
'
' Retrieving user input in VBScript
'************************************************
Option Explicit

Dim Message, result
Dim Title, Text1, Text2

' Define dialog box variables.
Message = "Please enter a path"           
Title = "WSH sample user input - by G. Born"
Text1 = "User input canceled"
Text2 = "You entered:" & vbCrLf

' Ready to use the InputBox function
' InputBox(prompt, title, default, xpos, ypos)
' prompt:    The text shown in the dialog box
' title:     The title of the dialog box
' default:   Default value shown in the text box
' xpos/ypos: Upper left position of the dialog box 
' If a parameter is omitted, VBScript uses a default value.

result = InputBox(Message, Title, "C:\Windows", 100, 100)

' Evaluate the user input.
If result = "" Then    ' Canceled by the user
    WScript.Echo Text1
Else 
    WScript.Echo Text2 & result
End If

'*** End

'result = InputBox(prompt[, [title], [default], [xpos], [ypos]])
'The InputBox function has the following parameters:
'prompt A required parameter that defines the message shown in the dialog box. In Figure 8-1, this is the string Please Enter A Path.
'title An optional parameter that defines the title bar text for the dialog box.
'default An optional parameter that specifies the default value shown in the text box.
'xpos and ypos Optional parameters that define the position of the upper left corner of the dialog box.
'InputBox("Hello", "Test", , 100, 200)
'If result = "" Then    ' Test for Cancel.
'    WScript.Echo "Canceled"
'Else 
'    WScript.Echo "You entered: " & result
'End If
---------------------------------------

http://wsh2.uw.hu/ch08b.html

http://www.instructables.com/id/How-to-Make-a-message-box-using-VBScript/


---------------------


Set objFSO=CreateObject("Scripting.FileSystemObject")

' How to write file
outFile="c:\test\autorun.inf"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write "test string" & vbCrLf
objFile.Close

'How to read a file
strFile = "c:\test\file"
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfStream
    strLine= objFile.ReadLine
    Wscript.Echo strLine
Loop
objFile.Close

'to get file path without drive letter, assuming drive letters are c:, d:, etc
strFile="c:\test\file"
s = Split(strFile,":")
WScript.Echo s(1)

------------------------------

Option Explicit

Const fsoForReading = 1
Const fsoForWriting = 2

Function LoadStringFromFile(filename)
    Dim fso, f
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.OpenTextFile(filename, fsoForReading)
    LoadStringFromFile = f.ReadAll
    f.Close
End Function

Sub SaveStringToFile(filename, text)
    Dim fso, f
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.OpenTextFile(filename, fsoForWriting)
    f.Write text
    f.Close
End Sub

SaveStringToFile "f.txt", "Hello World" & vbCrLf
MsgBox LoadStringFromFile("f.txt")

------------------------------------


'You can create a temp file, then rename it back to original file:

Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\test\file.txt"
strTemp = "c:\test\temp.txt"
Set objFile = objFS.GetFile(strFile)
Set objOutFile = objFS.CreateTextFile(strTemp,True)
Set ts = objFile.OpenAsTextStream(1,-2)
Do Until ts.AtEndOfStream
    strLine = ts.ReadLine
    ' do something with strLine 
    objOutFile.Write(strLine)
Loop
objOutFile.Close
ts.Close
objFS.DeleteFile(strFile)
objFS.MoveFile strTemp,strFile 


'Usage is almost the same using OpenTextFile:

Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\test\file.txt"
strTemp = "c:\test\temp.txt"
Set objFile = objFS.OpenTextFile(strFile)
Set objOutFile = objFS.CreateTextFile(strTemp,True)    
Do Until objFile.AtEndOfStream
    strLine = objFile.ReadLine
    ' do something with strLine 
    objOutFile.Write(strLine & "kndfffffff")
Loop
objOutFile.Close
objFile.Close
objFS.DeleteFile(strFile)
objFS.MoveFile strTemp,strFile 


------------------------------

http://stackoverflow.com/questions/1142678/read-and-write-into-a-file-using-vbscript

http://stackoverflow.com/questions/2198810/creating-and-writing-lines-to-a-file


--------------------------------------


The File System Object, generally used by VBScript developers to read and write text files, can read only ASCII or Unicode text files. You cannot use it to read or write UTF-8 encoded text files.

But, if you can use Microsoft ActiveX Data Objects (ADO), you can read UTF-8 encoded text files like this:

Dim objStream, strData
Set objStream = CreateObject("ADODB.Stream")
objStream.CharSet = "utf-8"
objStream.Open
objStream.LoadFromFile("C:\Users\admin\Desktop\test.txt")
strData = objStream.ReadText()
If you want to write a UTF-8 encode text file, you can do so like this:

Dim objStream
Set objStream = CreateObject("ADODB.Stream")
objStream.CharSet = "utf-8"
objStream.Open
objStream.WriteText "The data I want in utf-8"
objStream.SaveToFile "C:\Users\admin\Desktop\test.txt", 2


--------------------------------------


http://developer.rhino3d.com/guides/rhinoscript/read_write_utf8/