Category 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

 

Auto-conversion word to PDF on server side

There is a requirement for a system to convert a ms word file to PDF on server side.

References

  1. using libreoffice
  2. using python and openoffice

direct command

libreoffice --convert-to pdf /path/to/file.{doc,docx}
 OR
shell_exec('/usr/bin/libreoffice --headless --convert-to pdf:writer_pdf_Export --outdir /var/www/html/demo/public_html/src/var/output /var/www/html/demo/public_html/src/var/source/sample.doc');

OR

libreoffice --headless -convert-to pdf fileToConvert.docx -outdir output/path/for/pdf

above sample codes taken from different sources. Actually a similar command with some different optional parameters.

PHP array tips

Some tips.

1. Remove duplicates in array using array_unique

array array_unique ( array $array [, int $sort_flags = SORT_STRING ] )

2. Remove empty elements use array_filter

array array_filter ( array $array [, callable $callback [, int $flag = 0 ]] )

3. value is in the array use in_array

bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )

4. key exist in array use array_key_exist

bool array_key_exists ( mixed $key , array $array )

 

Web application security

Below are some security checklist for a web application.

  1. Login screen
    1. to avoid brute force attack, display captcha after 3-5 attempts from same IP
    2. enforce longer password more than 8
  2. Registration (or open form)
    1. display captcha for all form to submit
  3. SSL is a must. free or paid
  4. displaying primary id for table in URL must be avoided, use other ID instead. E.g. a secure id consisting of unique 10 randomized alphanumeric