Skip to content

Instantly share code, notes, and snippets.

@stopsatgreen
stopsatgreen / README.md
Created January 26, 2019 16:36
SCRIPT-8
Verifying that +stopsatgreen is my blockchain ID. https://onename.com/stopsatgreen
// Create new Promise
function get(url) {
return new Promise(function(resolve, reject) {
var req = new XMLHttpRequest();
req.open('GET', url);
req.onload = function() {
if (req.status == 200) {
resolve(req.response);
} else {
@stopsatgreen
stopsatgreen / php-get-json.php
Last active May 31, 2019 17:55
PHP: get JSON, with headers
<?php
// Because I don’t use PHP often enough to remember it instantly
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept: application/json"
)
);
$context = stream_context_create($opts);
@stopsatgreen
stopsatgreen / speech-synthesis
Created September 3, 2013 15:30
Web Speech API: Speech Synthesis. Works in Safari 6.1/7 only.
var foo = new SpeechSynthesisUtterance('Hello world');
window.speechSynthesis.speak(foo);
@stopsatgreen
stopsatgreen / Flexbox mixins
Last active December 20, 2015 05:09
A series of Sass mixins for working with legacy Flexbox properties.
//Flexbox
@mixin flex-display() {
display: -ms-flexbox;
display: -webkit-box;
display: -webkit-flex;
display: flex;
}
@mixin flex-align-items($arg: stretch) {
@stopsatgreen
stopsatgreen / html.sublime-snippet
Created March 27, 2013 15:04
A simple snippet for Sublime Text which creates a blank HTML template. Type 'html' + tab to run.
<snippet>
<content><![CDATA[
<!DOCTYPE HTML>
<html>
<head lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">
<title>[[TITLE GOES HERE]]</title>
<!-- Styles -->
@stopsatgreen
stopsatgreen / Placeholder Polyfill
Created December 18, 2012 10:09
Detect placeholder support in the browser and use value if it isn't present.
function hasPlaceHolder() {
return 'placeholder' in document.createElement('input');
}
function html5forms() {
var formPlaceholder = hasPlaceHolder();
if (formPlaceholder === false) {
$('input[type=text]').each(function() {
if($(this).attr('placeholder')) {
var placeholderText = $(this).attr('placeholder');
@stopsatgreen
stopsatgreen / AtoB
Last active December 9, 2015 20:58
Find the distance between two points, taking into account the curvature of the Earth.
function findDistance() {
'use strict';
var hasGeoLocation = navigator.geolocation ? true : false;
if (hasGeoLocation) {
var toLat, toLon, fromLat, fromLon, dLat, dLon, R, a, c, d, distance;
navigator.geolocation.getCurrentPosition(function(position) {
// Define the toRad function for later calculation
if (typeof(Number.prototype.toRad) === 'undefined') {
Number.prototype.toRad = function() {
return this * Math.PI / 180;