Skip to content

Instantly share code, notes, and snippets.

View filipkral's full-sized avatar

Filip Kral filipkral

View GitHub Profile
@filipkral
filipkral / convert_xml_codes.py
Last active August 29, 2015 14:03
Convert XML codes from Unicode to string and back in Python
# How to convert XML codes for Unicode can be translated to Unicode in Python
# This is useful for example when reading/writing from/to attribute tables in ArcGIS
import HTMLParser
parser = HTMLParser.HTMLParser()
unescaped = parser.unescape('Krinelnàch')
# To convert from Unicode to xml do:
escaped = u'Krineln\xe0ch'.encode('ascii', 'xmlcharrefreplace')
@filipkral
filipkral / python-cheat-sheet-basic.py
Last active March 12, 2023 12:30
Basic Python Cheat Sheet
#!/usr/bin/env python
"""Basic Python Cheat Sheet by Filip Kral on 2015/02/16"""
"""
Python is a cross-platform, interpreted, object-oriented programming language.
That means you can run it on Linux, Windows, Mac, and other platforms,
you don't need to compile your code to execute it because it is compiled on
the fly, and you can use classes and objects.
@filipkral
filipkral / gist:45b49cad4d23fb211632
Created May 30, 2014 15:36
basic jQuery get, post, ajax
// get
function yay(a,b,c){ console.log(['yay', a, b, c]); }
function nay(a,b,c){ console.log(['nay', a, b, c]); }
$.get({url: 'http://foo.bar/spam?eggs=1', dataType:'jsonp'}).done( yay ).fail( nay );
$.post("http://foo.bar/spam", {eggs: 1} ).done( yay ).fail( nay );
var jqxhr = $.ajax( {url:"http://foo.bar/spam", data: {}, method: 'GET', dataType: 'jsonp'}).done( yay ).fail( nay ).always(function() { console.log( "always" ); });
@filipkral
filipkral / gist:7441074
Created November 13, 2013 00:04
Stay on page. I use this to prevent me from leaving ArcGIS API for JavaScript Sandbox (http://developers.arcgis.com/en/javascript/sandbox/sandbox.html) accidentally by pressing escape when the focus is not on the code editor.
// to open a confirm dialog before you leave the page, enter this into the browser console (or the javascript code)
window.onbeforeunload = function(e){ var e = e || window.event; var msg ="Don't leave!"; if(e){e.returnvalue = msg;} return msg; }