Tag Archives: programming

Learning Vue

Some notes taken while learning vue.

to start using vue can include this file.

<script src=”https://unpkg.com/vue”></script>

Vue object

  • el: “#id – define the element
  • data – define data
  • methods – define method/functions

Vue Directives

  • v-bind – can bind to any attribute in element. e.g. class, title, type, style, href
    • v-bind is use to control the html element attribute where “moustache {{ }}” cannot be used
    • example <div v-bind:class=“{ active: isActive }”></div>
  • v-if=”status”
  • v-for=“item in items” – normally use with <li> elements
  • v-on – example <button v-on:click=”callAFunction”>click me</button>
  • v-model (2 way data binding). example <input v-model=“message”>. message can be displayed as {{ message }} and can be data inside vue script
  • guide/tutorial on directive
  • full list of directives

Vue Components

Vue.component (‘name’, {


  • first argument – name of the component
  • props
  • template

API reference

vue cheat sheet


Ways to avoid duplicates due to browser refresh

Below are scenarios that may cause duplicates

  1. browser refresh upon successful form submission
  2. browser refresh while the page still processing/loading
  3. resubmit the form again (by clicking on the button more than once)


  1. Post-redirect-get (PRG) – on wikipedia
  2. One easy way is to have injected a hidden parameter with a random hash/number (e.g called token). Upon submission you’ll have to check that the token you expect (which you’ll have probably stored in the http session) is being sent together with the other POST parameters. On valid submission you’ll remove/invalidate this token. That way when a POST comes which a non recognised token then it’s most probably a duplicate or out of date request. source
  3. To check whether the data submitted exist in the database. This is the most tedious part to do and you need to have a unique data for this. i.e. the data must be unique in the table or create a unique data for this purpose sent together with other data.
  4. Add a one-time token to your forms and save it to the $_SESSION-variable. Then if it is used (form is submitted), remove it from the session (or create a new token). If the form is then sent again, the two tokens don’t match and you have a duplicate entry (you can ignore the second for example). source 


How to easily create PHP image gallery

This becoming my favorite image gallery now – fotorama.io. So easy to implement with plenty of customization that we can do.

If you don’t believe how easy it is, copy following source code, paste and save as an html file. Then open it and see what will happen.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.3/fotorama.css" rel="stylesheet">
<script src="http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.3/fotorama.js"></script>

<div class="fotorama" data-width="100%" data-ratio="800/600" data-nav="thumbs" data-loop="true" data-allowfullscreen="true">
 <img src="http://s.fotorama.io/1.jpg">
 <img src="http://s.fotorama.io/2.jpg">




PHP script to get domain from URL string

Sometimes maybe you need to get a domain name from a URL string. Here is the code

function GetDomain($url)
$nowww = ereg_replace(’www.,,$url);
$domain = parse_url($nowww);
     return $domain["host"];
     } else
     return $domain["path"];