This page has the following setup.
/*
extracted from "Templates"
(http://www.cplusplus.com/doc/tutorial/templates.html)
*/
// sequence template
#include <iostream>
using namespace std;
template <class T, int N>
class mysequence {
T memblock [N];
public:
void setmember (int x, T value);
T getmember (int x);
};
template <class T, int N>
void mysequence<T,N>::setmember (int x, T value) {
memblock[x]=value;
}
template <class T, int N>
T mysequence<T,N>::getmember (int x) {
return memblock[x];
}
int main () {
mysequence <int,5> myints;
mysequence <double,5> myfloats;
myints.setmember (0,100);
myfloats.setmember (3,3.1416);
cout << myints.getmember(0) << '\n';
cout << myfloats.getmember(3) << '\n';
return 0;
}
/*
extracted from "Introducing Generics in the CLR"
(http://msdn.microsoft.com/msdnmag/issues/03/09/NET/)
*/
using System;
// Definition of a node type for creating a linked list
class Node {
Object m_data;
Node m_next;
public Node(Object data, Node next) {
m_data = data;
m_next = next;
}
// Access the data for the node
public Object Data {
get { return m_data; }
}
// Access the next node
public Node Next {
get { return m_next; }
}
// Get a string representation of the node
public override String ToString() {
return m_data.ToString();
}
}
// Code that uses the node type
class App {
public static void Main() {
// Create a linked list of integers
Node head = new Node(5, null);
head = new Node(10, head);
head = new Node(15, head);
// Sum-up integers by traversing linked list
Int32 sum = 0;
for (Node current = head; current != null;
current = current.Next) {
sum += (Int32) current.Data;
}
// Output sum
Console.WriteLine("Sum of nodes = {0}", sum);
}
}
(*
extracted from "Avoiding memory leaks"
(http://www.delphibasics.co.uk/Article.asp?Name=Memory)
*)
unit MyClass;
interface
uses
Classes;
type
TMyClass = class
private
fileData : TStringList;
published
Constructor Create(const fileName : string);
Destructor Destroy; override;
procedure PrintFile;
end;
implementation
uses
Printers, Dialogs, SysUtils;
// Constructor - builds the class object
constructor TMyClass.Create(const fileName: string);
begin
// Create the string list object used to hold the file contents
fileData := TStringList.Create;
// And load the file data into it
try
fileData.LoadFromFile(fileName);
except
ShowMessage('Error : '+fileName+' file not found.');
end;
end;
// Destructor - frees up memory used by the class object
destructor TMyClass.Destroy;
begin
// Free up the memory used by the string list object
FreeAndNil(fileData);
// Call the parent class destructor
inherited;
end;
// Print the file passed to the constructor
procedure TMyClass.PrintFile;
var
myFile : TextFile;
i : Integer;
begin
// Open a printer file
AssignPrn(myFile);
// Now prepare to write to the printer
ReWrite(myFile);
// Write the lines of the file to the printer
for i := 0 to fileData.Count-1 do
WriteLn(myFile, fileData[i]);
// Close the print file
CloseFile(myFile);
end;
end.
/*
extracted from "Reference Objects and Garbage Collection"
(http://java.sun.com/developer/technicalArticles/ALT/RefObj/index.html)
*/
import java.awt.Graphics;
import java.awt.Image;
import java.applet.Applet;
import java.lang.ref.SoftReference;
public class DisplayImage extends Applet {
SoftReference sr = null;
public void init() {
System.out.println("Initializing");
}
public void paint(Graphics g) {
Image im = (
sr == null) ? null : (Image)(
sr.get());
if (im == null) {
System.out.println(
"Fetching image");
im = getImage(getCodeBase(),
"truck1.gif");
sr = new SoftReference(im);
}
System.out.println("Painting");
g.drawImage(im, 25, 25, this);
im = null;
/* Clear the strong reference to the image */
}
public void start() {
System.out.println("Starting");
}
public void stop() {
System.out.println("Stopping");
}
}
%REM
extracted from "OLE constants"
(https://mondotondo.com/projects/post/ole-constants/)
%END REM
'Install tlbinf32.dll:
Option Public
Option Declare
Use "RegistryAccess"
Sub Initialize
%INCLUDE "error_handling"
Dim tli As Variant
On Error Resume Next
Set tli = CreateObject( "TLI.TLIApplication" )
On Error Goto HandleError
If Err = 0 Then
Set tli = Nothing
Exit Sub
End If
Dim instalar As String
instalar = "tlbinf32.dll"
Dim s As New NotesSession
Dim db As NotesDatabase
Set db = s.CurrentDatabase
Dim d As notesdocument
Set d = GetHelpAboutDocument( db, instalar )
If d Is Nothing Then
Msgbox "The library " & instalar & " has not been installed" & Chr( 10 ) _
& "The library could not be found in the database" & Chr( 10 ) _
& "Please notify your admin"
Exit Sub
End If
Dim systemRoot As String
systemRoot = RegQueryValue( "HKEY_LOCAL_MACHINE", "SOFTWAREMicrosoftWindows NTCurrentVersion", "SystemRoot" )
Dim path As String
path = systemRoot & "system32" & instalar
Call ExtractAttachment( d, instalar, path )
If Dir( path ) = "" Then
Msgbox "The library " & instalar & " has not been installed" & Chr( 10 ) _
& "The library could not be put in the folder " & path & Chr( 10 ) _
& "Please notify your admin"
Exit Sub
End If
If Shell( "regsvr32 /s " & instalar ) <> 33 Then
Msgbox "The library " & instalar & " has not been installed" & Chr( 10 ) _
& "The library could not be registered" & Chr( 10 ) _
& "Please notify your admin"
Exit Sub
End If
Msgbox "The library " & instalar & " has been installed"
' HKEY_CLASSES_ROOTCLSID{8B217746-717D-11CE-AB5B-D41203C10000}InprocServer32
End Sub
Function GetHelpAboutDocument( db As NotesDatabase, filename As String ) As NotesDocument
%INCLUDE "error_handling"
Dim nc As NotesNoteCollection
Set nc = db.CreateNoteCollection( False )
nc.SelectHelpAbout = True
Call nc.BuildCollection
Dim nid As String
nid = nc.GetFirstNoteId
If nid <> "" Then
Set GetHelpAboutDocument = db.GetDocumentByID( nid )
Else
Set GetHelpAboutDocument = Nothing
End If
End Function
Sub ExtractAttachment( d As NotesDocument, filename As String, path As String )
%INCLUDE "error_handling"
If Not d.HasEmbedded Then Exit Sub
Dim embedded As NotesEmbeddedObject
Set embedded = d.GetAttachment( filename )
If embedded Is Nothing Then Exit Sub
Call embedded.ExtractFile( path )
End Sub
/*
extracted from "Advanced MySQL user variable techniques"
(http://www.xaprb.com/blog/2006/12/15/advanced-mysql-user-variable-techniques/)
*/
CREATE TABLE fruits (
`type` varchar(10) NOT NULL,
variety varchar(20) NOT NULL,
price decimal(5,2) NOT NULL default 0,
PRIMARY KEY (`type`,variety)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
insert into fruits(`type`, variety, price) values
('apple', 'gala', 2.79),
('apple', 'fuji', 0.24),
('apple', 'limbertwig', 2.87),
('orange', 'valencia', 3.59),
('orange', 'navel', 9.36),
('pear', 'bradford', 6.05),
('pear', 'bartlett', 2.14),
('cherry', 'bing', 2.55),
('cherry', 'chelan', 6.33);
set @num := 0, @type := '';
select `type`, variety, price, @num
from fruits
where 2 >= greatest(
@num := if(@type = `type`, @num + 1, 1),
least(0, length(@type := `type`)));