Script

Filter
2003-10-17

Image toolbar

Html
Liten kodsnutt som tar bort toolbar från bilder i MSIE
<meta http-equiv="imagetoolbar" content="no">
<!-- eller i img-attribut: galleryimg="no" --> 
2003-10-09

Dynamisk Aplet

Javascript
Tar reda på webläsarens storlek och anpassar en javas storlek
<html>
<head>
<title>Resizable Applet</title>
</head>
<body onResize="location.reload();">
<script language="javascript">
if(navigator.appName=="Netscape") {
    winW = window.innerWidth;
    winH = window.innerHeight;
} else if(navigator.appName.indexOf("Microsoft")!=-1) {
    winW = document.body.offsetWidth;
    winH = document.body.offsetHeight;
}
document.write("<applet code=\"Applet.class\" +
" width=" + (winW-50) + 
" height=" + (winH-50) + "></applet>");
</script>
</body>
</html>
2003-09-16

Slumptal

Asp
Generell slumpfunktion
<%
' Ex mellan 10 till 20
upper = 20
lower = 10
randomize
slumptal = int((upper + 1 - lower) * rnd() + lower)
%>
2003-09-15

Sortering

Java
Binary search of a sorted list
// Using 2 overloaded methods to recursively search
// a list of integers. The list must be sorted.

public static int binarySearch(int key, int[] list) {
  int low = 0;
  int high = list.length - 1;
  return binarySearch(key, list, low, high);
}

public static int binarySearch(int key, int[] list, int low, int high) {
  if (low > high)
    return -1; // no match
  int mid = (low + high) / 2;
  if (key < list[mid])
    return binarySearch(key, list, low, mid - 1);
  else if (key == list[mid])
    return mid;
  else
    return binarySearch(key, list, mid + 1, high);
} 
2003-09-15

Sortering

Java
Sorting an array with selection sort
// Sorting an array of doubles using selection sort:
// Find the largest number in the list and place
// it last. Then, find the largest number remaining
// and place it next to last, and so on until the
// list only contains one number.

static void selectionSort(double[] list) {
  for (int i = list.length - 1; i >= 1; i--) {
    double currentMax = list[0];
    int currentMaxIndex = 0;

    for (int j = 1; j <= i; j++) {
      if (currentMax < list[j]) {
        currentMax = list[j];
        currentMaxIndex = j;
      }
    }

    if (currentMaxIndex != i) {
      list[currentMaxIndex] = list[i];
      list[i] = currentMax;
    }
  }
} 
🙂