lunedì 25 settembre 2017

Redirect in Livecode

Se usate livecode in un web server, potete utilizzarlo anche per i redirect, vi basta del codice come:
<?lc
  put "http://www.google.com" into tURL 
  put header "Status: 301"
  put header "Location:" && tURL 
  put "redirecting..." 
?>

E il redirect è servito (nell'esempio verso Google).

giovedì 21 settembre 2017

Dark Sky API

Dark Sky è un servizio che permette di avere tutte le informazione sulle previsione meteorologiche presenti, passate e future di qualsiasi parte del mondo in qualsiasi lingua.
Ho provato ad interfacciarmi con livecode ed è semplicissimo, lanciate un semplice URL e la risposta è in file Json con tutti i dati.
Vi allego un link del programma qui sotto che ho fatto, ricordatevi di registrarvi e mettere la vostra chiave di Dark Sky: https://mega.nz/#!0NRk1bLA!HqZD012NGKIABNMwO9LGavkip3SLT2jJpbn9yegxdCg

martedì 19 settembre 2017

Dash

Dash è un programma per Mac e iOS per avere la documentazione di qualunque pezzo di software, vi dice ogni funzione o classe cosa sia. E' stato realizzato in livecode.
Supporta più di 150 linguaggi e 400 sintassi.
Si integra con i maggiori IDE.
Lo potete trovare qui: https://kapeli.com/dash
Ecco alcune immagini di come funziona:




giovedì 7 settembre 2017

Usare livecode server per modificare le immagini

Livecode server permette anche di lavorare le immagini come nei programmi normali generati da livecode.
Il seguente codice per esempio vi permette di caricare un'immagine e modificarla, vi servono solo sue file, la pagina iniziale chiamata manip.lc, così scritta:

<?lc
start session


## enter the image file into our $_SESSION if one's just been
# uploaded
if $_FILES["imagefile"] is not empty then
   put url("binfile:" & $_FILES["imagefile"]["filename"]) into $_SESSION["imagedata"]
end if

if $_SESSION["imagedata"] is empty then
   printForm ## no image has been uploaded so display the form to upload one
else
   create image "myImage"
   set the lockLoc of image "myImage" to true
   set the text of image "myImage" to $_SESSION["imagedata"]
   
   repeat for each key tOption in $_POST
      if $_POST[tOption] is not empty then applyOption tOption
   end repeat
   
   if $_SESSION["random"] is empty then
      put random(10000000) into $_SESSION["random"]
   end if
   export snapshot from image "myImage" to file ($_SESSION["random"] & ".png") as PNG
   
   put "<img src=" & quote & ($_SESSION["random"] & ".png") & quote & "></img><br><br>"
   
   put url("binfile:" & $_SESSION["random"] & ".png") into $_SESSION["imagedata"]
   
   printOptions
end if

## apply an option to the image
on applyOption pOption   
   switch pOption
      case "width"
         if $_POST["width"] is not a number then
            put "WIDTH NEEDS TO A NUMBER<br>"
         else
            set the width of image "myImage" to $_POST["width"]
         end if
         break
      case "height"
         if $_POST["height"] is not a number then
            put "HEIGHT NEEDS TO BE A NUMBER<br>"
         else
            set the height of image "myImage" to $_POST["height"]
         end if
         break
      case "huestrip"
         put the imageData of image "myImage" into tImageDat
         repeat with x = $_POST["huestrip"] to the number of chars in tImageDat step 4
            put numtochar(0) into char x of tImageDat
         end repeat
         set the imageData of image "myImage" to tImageDat
         break
      case "hueadd"
         if ($_POST["hueadd"] >= 0) and ($_POST["hueadd"] <= 255) then
            put the imageData of image "myImage" into tImageDat
            repeat with x = $_POST["hueadd"] to the number of chars in tImageDat step 4
               put numtochar($_POST["saturation"]) into char x of tImageDat
            end repeat
            set the imageData of image "myImage" to tImageDat
         else
            put "NEEDS TO BE AN INTEGER 0-255"
         end if
         break
   end switch   
end applyOption

## print photo manipulation options
on printOptions
   
   put "<p>Set image dimensions<br>"
   put "<p><form action='manip.lc' method='post'>"
   put "<input type='text' name='width'>"
   put "<input type='text' name='height'>"
   put "<input type='submit' value='Apply'>"
   put "</form></p>"
   
   
   put "<p>Strip a hue from the image<br>"
   put "<form action='manip.lc' method='post'>"
   put "<input type='radio' name='huestrip' value='2'>Red"
   put "<input type='radio' name='huestrip' value='3'>Green"
   put "<input type='radio' name='huestrip' value='4'>Blue"
   put "<input type='submit' value='apply'>"
   put "</form></p>"
   
   put "<p>Add Color<br>"
   put "<form action='manip.lc' method='post'>"
   put "<input type='radio' name='hueadd' value='2'>Red"
   put "<input type='radio' name='hueadd' value='3'>Green"
   put "<input type='radio' name='hueadd' value='4'>Blue"
   put "<input type='text' name='saturation'>Saturation"
   put "<input type='submit' value='apply'>"
   put "</form></p>"
   
   put "<a href='logout.lc'>Reset Session</a>"   
end printOptions

## print upload form
on printForm
   put "Upload an image:<br>"
   put "<form action='manip.lc' enctype='multipart/form-data' method='post'>"
   put "<input type='file' name='imagefile'><br>"
   put "<input type='submit' value='upload'>"
   put "</form>"
end printForm

stop session
?>

Che vi serve per caricare l'immagine e modificarla come ci pare:



e poi una pagina per distruggere la sessione che contiene l'immagine altri dati, chiamata logout.lc:
<?lc 
 delete session 
 put "<b>Session deleted</b><br>" 
 ?> 
<a href=manip.lc > Start again</a>

Tutto testato e verificato: funziona!

venerdì 1 settembre 2017

Autocompletamento del codice

Livecode ha introdotto l'autocompletamento del codice, ecco un video dimostrativo:
Vi piace?