Monatsarchiv für May 2011

 
 

PHP File Loads Itself

This is weird idea I had right before I went to sleep last night. I might actually use it for something… have a look:

loadme.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
<?php
  $file = file_get_contents("loadme.php");
 
  $file = preg_split("/\?\>\n/", $file);
  $file = preg_replace("/^/m", "z",$file[1]);
 
  echo $file;
 
  die();
?>
one
two
three
four
 
'; ?>

The above just adds a z in front of each new line. So it outputs:

zone ztwo zthree zfour

It could be used for preprocessing a document. Something like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
<?php require_once("processor.php"); ?>;
 
html
  head
    meta charset="utf-8"
    title (test site)
 
  body
     #nav
       .btn(one) .btn(two) .btn(three)
 
     #left (left side)
 
     #center
        .entry
          h1(Hello This is an entry)
          (this is some text)
        .entry
          h1(Another Entry)
          (more text)
 
     #right (right side)
 
     #footer (Vorbin Saucer 2012)

The php would then turn the above markup into regular html. Kind of interesting…

Is jQuery Making Javascript Devs Stupid?

No it isn’t.

It has become a sort of gateway for people who want to do things with javascript but don’t know much about programming. These people ask lots of questions on sites like stackoverflow and surprisingly generous, knowledgable, experienced, programmers answer. I don’t see anything wrong with that… many of these beginners will go on to become good programmers.

There are lots of weird misconceptions about jQuery – but anyone who spends a few hours playing with the library will realize these things aren’t true.

I really like jQuery. It’s one of my favorite libraries – right up there with Box2D, TweenLite, PaperVision and Raphael. It’s saved me hours on commercial projects, provided hours of entertainment and I’ve learned a bunch of interesting stuff from browsing through the source code.

The idea for this post came from a skribit suggestion. Thanks to the person that suggested it.

jQuery.html()

Most of the time jQuery.html() is used to just set all the html() in an html element. Very useful for all kinds of stuff. Sometimes though, you want to process and alter the html inside a given element. This can be done by passing a function to html(). Below I put bold tags around the words “data”, “the”, “SVM” and “SVNs”.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!DOCTYPE html>
<html> 
  <head> 
    <meta charset="utf-8" />
    <title>Html Function</title> 
    <script src="http://code.jquery.com/jquery-1.5.1.min.js"></script>
 
    <script>
      $(function(){
 
        $("p").html(function(i, htm){
          return htm.replace(/\\b(data|the|SVM[s]?)\\b/g, "<b>$1<\/b>");
        });
 
      });
    </script>
    <style>
      b{
        color : red; 
      }
    </style>
  </head> 
 
  <body> 
    <p>
      In computer science, support vector machines (SVMs) are a set of related supervised learning methods that analyze data and recognize patterns, used for classification and regression analysis. The original SVM algorithm was invented by Vladimir Vapnik and the current standard incarnation (soft margin) was proposed by Corinna Cortes and Vladimir Vapnik.[1] The standard SVM takes a set of input data and predicts, for each given input, which of two possible classes the input is a member of, which makes the SVM a non-probabilistic binary linear classifier. Since an SVM is a classifier, then given a set of training examples, each marked as belonging to one of two categories, an SVM training algorithm builds a model that assigns new examples into one category or the other. Intuitively, an SVM model is a representation of the examples as points in space, mapped so that the examples of the separate categories are divided by a clear gap that is as wide as possible. New examples are then mapped into that same space and predicted to belong to a category based on which side of the gap they fall on.
    </p>
    <p>
      More formally, a support vector machine constructs a hyperplane or set of hyperplanes in a high or infinite dimensional space, which can be used for classification, regression, or other tasks. Intuitively, a good separation is achieved by the hyperplane that has the largest distance to the nearest training data points of any class (so-called functional margin), since in general the larger the margin the lower the generalization error of the classifier.
    </p>
  </body> 
</html>

The result looks like this:

This text is from wikipedia’s entry on Support Vector Machines.