Removes a file
rm app.js
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
if (typeof window.DeviceMotionEvent != 'undefined') | |
{ | |
// Shake sensitivity (a lower number is more) | |
var sensitivity = 15; | |
// Position variables | |
var x1 = 0, y1 = 0, z1 = 0, x2 = 0, y2 = 0, z2 = 0; | |
// Listen to motion events and update the position | |
window.addEventListener('devicemotion', function (e) |
/* | |
* Taken from http://stackoverflow.com/questions/5867534/how-to-save-canvas-data-to-file/5971674#5971674 | |
*/ | |
var fs = require('fs'); | |
// string generated by canvas.toDataURL() | |
var img = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0" | |
+ "NAAAAKElEQVQ4jWNgYGD4Twzu6FhFFGYYNXDUwGFpIAk2E4dHDRw1cDgaCAASFOffhEIO" | |
+ "3gAAAABJRU5ErkJggg=="; | |
// strip off the data: url prefix to get just the base64-encoded bytes |
<?php | |
// requires php5 | |
define('UPLOAD_DIR', 'images/'); | |
$img = $_POST['img']; | |
$img = str_replace('data:image/png;base64,', '', $img); | |
$img = str_replace(' ', '+', $img); | |
$data = base64_decode($img); | |
$file = UPLOAD_DIR . uniqid() . '.png'; | |
$success = file_put_contents($file, $data); | |
print $success ? $file : 'Unable to save the file.'; |
drag: function () { | |
function startDrag(e) { | |
// determine event object | |
if (!e) { | |
var e = window.event; | |
} | |
if(e.preventDefault) e.preventDefault(); | |
// IE uses srcElement, others use target | |
targ = e.target ? e.target : e.srcElement; |
var maxWidth = 304; // Max width for the image | |
var maxHeight = 338; // Max height for the image | |
var ratio = 0; // Used for aspect ratio | |
var width = img.width; // Current image width | |
var height = img.height; // Current image height | |
var image = document.getElementById('userImage'); | |
image.style.width = width + 'px'; | |
image.style.height = height + 'px'; |
function getOrientation(file, callback) { | |
var reader = new FileReader(); | |
reader.onload = function (e) { | |
var view = new DataView(e.target.result); | |
if (view.getUint16(0, false) != 0xFFD8) return callback(-2); | |
var length = view.byteLength, offset = 2; | |
while (offset < length) { | |
var marker = view.getUint16(offset, false); | |
offset += 2; |
// This needs tidied up before production TODO | |
var country_list = ["Afghanistan","Albania","Algeria","Andorra","Angola","Anguilla","Antigua & Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas" | |
,"Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia & Herzegovina","Botswana","Brazil","British Virgin Islands" | |
,"Brunei","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Cape Verde","Cayman Islands","Chad","Chile","China","Colombia","Congo","Cook Islands","Costa Rica" | |
,"Cote D Ivoire","Croatia","Cruise Ship","Cuba","Cyprus","Czech Republic","Denmark","Djibouti","Dominica","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea" | |
,"Estonia","Ethiopia","Falkland Islands","Faroe Islands","Fiji","Finland","France","French Polynesia","French West Indies","Gabon","Gambia","Georgia","Germany","Ghana" | |
,"Gibraltar","Greece","Greenland","Grenada","Guam","Guatemala","Guernsey","Guinea","Guinea Bis |
{ | |
"countries": [ | |
{ | |
"country": "Afghanistan", | |
"states": ["Badakhshan", "Badghis", "Baghlan", "Balkh", "Bamian", "Daykondi", "Farah", "Faryab", "Ghazni", "Ghowr", "Helmand", "Herat", "Jowzjan", "Kabul", "Kandahar", "Kapisa", "Khost", "Konar", "Kondoz", "Laghman", "Lowgar", "Nangarhar", "Nimruz", "Nurestan", "Oruzgan", "Paktia", "Paktika", "Panjshir", "Parvan", "Samangan", "Sar-e Pol", "Takhar", "Vardak", "Zabol"] | |
}, | |
{ | |
"country": "Albania", | |
"states": ["Berat", "Dibres", "Durres", "Elbasan", "Fier", "Gjirokastre", "Korce", "Kukes", "Lezhe", "Shkoder", "Tirane", "Vlore"] | |
}, |