Skip to content

Instantly share code, notes, and snippets.

@alamsal
alamsal / PasswordHelper.cs
Created August 10, 2016 18:35
Databind the Password Property of a WPF PasswordBox
public static class PasswordHelper
{
public static readonly DependencyProperty PasswordProperty =
DependencyProperty.RegisterAttached("Password",
typeof(string), typeof(PasswordHelper),
new FrameworkPropertyMetadata(string.Empty, OnPasswordPropertyChanged));
public static readonly DependencyProperty AttachProperty =
DependencyProperty.RegisterAttached("Attach",
typeof(bool), typeof(PasswordHelper), new PropertyMetadata(false, Attach));
@alamsal
alamsal / index.html
Last active April 26, 2016 20:56
Leaflet custom projection
<!DOCTYPE html>
<html>
<head>
<title>Leaflet custom projection example</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-0.7/leaflet.css" />
<script src="//cdn.leafletjs.com/leaflet-0.7/leaflet-src.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/proj4js/2.0.0/proj4.js"></script>
<script src="//mapserv.utah.gov/cdn/examples/proj4leaflet.js"></script>
@alamsal
alamsal / index.html
Created March 3, 2016 20:22
ESRI Leaflet Dynamic Map Layer With Map Tiles
<!DOCTYPE html>
<html>
<head>
<title>ESRI Leaflet Dynamic Map Layer With Map Tiles</title>
<meta charset="utf-8" />
<link
rel="stylesheet"
href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css"
/>
</head>
@alamsal
alamsal / ReadAsArrayCsharp.cs
Last active September 3, 2015 21:26
GDAL: Python's alternative to ReadAsArray in C#
//Let's assume you read pixels of a band with width x height dimensions:
byte[] bits = new byte[width * height];
band.ReadRaster(0, 0, width, height, bits, width, height, 0, 0);
//Now, you can calculate index of a pixel according to this formula: column + row * width
for (int col = 0; col < width; col++)
{
for (int row = 0; row < height; row++)
@alamsal
alamsal / distanceFinder.js
Created August 31, 2015 18:55
Find out location with in X radius from the user's current location
function distance(obj) {
var R = 6371; // km
var dLat = (obj.lat2 - obj.lat1) * Math.PI / 180;
var dLon = (obj.lon2 - obj.lon1) * Math.PI / 180;
var lat1 = obj.lat1 * Math.PI / 180;
var lat2 = obj.lat2 * Math.PI / 180;
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
@alamsal
alamsal / UrlStatusChecker.py
Created August 24, 2015 05:52
Check if URL is dead or live
import httplib
from urlparse import urlparse
def checkUrl(url):
p = urlparse(url)
conn = httplib.HTTPConnection(p.netloc)
conn.request('HEAD', p.path)
resp = conn.getresponse()
return resp.status < 400
@alamsal
alamsal / README.md
Last active August 29, 2015 14:27 — forked from rveciana/README.md
D3 tutorial V: Adding tooltips
@alamsal
alamsal / forestSpecies.json
Created August 21, 2015 15:52
Forest species wheel in d3.js
{
"name" : "",
"children" :
[
{
"name" : "Softwoods",
"children" :
[
{
"order" : 1,
@alamsal
alamsal / forestSpecies.json
Created August 13, 2015 17:41
Collapsible forest species dendrogram
{
"name" : "",
"children" :
[
{
"name" : "Softwoods",
"children" :
[
{
"order" : 1,
@alamsal
alamsal / README.md
Last active August 29, 2015 14:27 — forked from sgruhier/README.md

Simplest way to add pan/zoom to a d3js visualisation