Skip to content

Instantly share code, notes, and snippets.

@domenic
domenic / HTMLMediaElement.js
Created October 14, 2014 15:51
HTMLMediaElement.js skeleton
import conversions from "webidl-conversions";
import reflector from "webidl-html-reflector";
var defineProperty = Object.defineProperty;
export default class CustomHTMLMediaElement extends HTMLElement {
get error() {}
get src() {
return reflector["DOMString"].get(this, "src");
}
set src(v) {
v = conversions["DOMString"](v);
@ralphschindler
ralphschindler / array_walk_recursive_key.php
Created September 19, 2014 14:59
Apply user functions to both keys and values while recursively walking an associative array
<?php
function array_walk_recursive_key(array $array, callable $valueCallback, callable $keyCallback = null) {
foreach ($array as $n => &$v) {
$n2 = ($keyCallback) ? $keyCallback($n) : $n;
if ($n != $n2) {
$array[$n2] = &$array[$n];
unset($array[$n]);
}
if (is_array($v)) {
@techslides
techslides / github-gist-api.js
Last active January 1, 2022 23:03
GitHub API to make Gists with Ajax
/*
Assuming jQuery Ajax instead of vanilla XHR
*/
//Get Github Authorization Token with proper scope, print to console
$.ajax({
url: 'https://api.github.com/authorizations',
type: 'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("USERNAME:PASSWORD"));
@gordonbrander
gordonbrander / search-and-replace.js
Created July 19, 2014 04:20
searchAndReplace(string, pattern, step): step through RegExp matches and generate replacements with callback that has full access to string indexes.
// Splice in a string between `begin` and `end` indexes.
// Returns a new string.
function spliceString(string, insert, begin, end) {
return string.slice(0, begin) + insert + string.slice(end);
}
// Search a string with a regular expression, where `step` callback will
// be called at each match, allowing you to perform extra logic and create a
// replacement string.
//
// Highcharts CheatSheet Part 1.
// Create interactive charts easily for your web projects.
// Download: http://www.highcharts.com/download
// More: http://api.highcharts.com/highcharts
// 1. Installation.
// Highcharts requires two files to run, highcharts.js and either jQuery, MooTools or Prototype or the Highcharts Standalone Framework which are used for some common JavaScript tasks.
// <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
// <script src="https://code.highcharts.com/highcharts.js"></script>
# NPM CheatSheet.
# Super easy intall: npm comes with node now.
# To create your own npm package: https://www.npmjs.org/doc/misc/npm-developers.html
# More: https://www.npmjs.org/doc/
# 1. NPM Command Lines.
# Local mode is the default.
# Use --global or -g on any command to operate in global mode instead.
@andrejbauer
andrejbauer / topology.v
Last active November 28, 2023 19:40
How to get started with point-set topology in Coq. This is not actually how one would do it, but it is an intuitive setup for a classical mathematician.
(* How do to topology in Coq if you are secretly an HOL fan.
We will not use type classes or canonical structures because they
count as "advanced" technology. But we will use notations.
*)
(* We think of subsets as propositional functions.
Thus, if [A] is a type [x : A] and [U] is a subset of [A],
[U x] means "[x] is an element of [U]".
*)
Definition P (A : Type) := A -> Prop.
@julien-f
julien-f / index.js
Last active June 2, 2017 06:51
d3.js in Node.js
/**
* > npm install d3
*/
// In Node.js, d3.js works in a virtual document provided by jsdom.
var d3 = require('d3');
//--------
// Create the SVG element.
module AI.Search.Examples.Graph where
import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Data.STRef
import Data.Map (Map, (!))
import qualified Data.Map as Map
import Data.List (nub)
import Data.Graph.Inductive (LNode, LEdge, Gr)
@5outh
5outh / DeMorgan.hs
Created November 13, 2013 17:04
DeMorgan
{-# LANGUAGE NoMonomorphismRestriction #-}
import Text.ParserCombinators.Parsec
import Text.ParserCombinators.Parsec.Token hiding (parens)
import Text.ParserCombinators.Parsec.Expr
import Control.Applicative hiding ((<|>))
import Control.Monad
import Prelude hiding (not)
data Expr = Not Expr | And Expr Expr | Or Expr Expr | Var Char | SubExpr Expr deriving Eq