This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// selection range | |
var range = window.getSelection().getRangeAt(0); | |
// plain text of selected range (if you want it w/o html) | |
var text = window.getSelection(); | |
// document fragment with html for selection | |
var fragment = range.cloneContents(); | |
// make new element, insert document fragment, then get innerHTML! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hslToRgb = function(_h, s, l) { | |
var h = Math.min(_h, 359)/60; | |
var c = (1-Math.abs((2*l)-1))*s; | |
var x = c*(1-Math.abs((h % 2)-1)); | |
var m = l - (0.5*c); | |
var r = m, g = m, b = m; | |
if (h < 1) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Credit to @steobrien from https://gist.github.com/rmehner/b9a41d9f659c9b1c3340#gistcomment-2940034 | |
// for modern browsers, this works: | |
const dbs = await window.indexedDB.databases() | |
dbs.forEach(db => { window.indexedDB.deleteDatabase(db.name) }) | |
// for older browsers, have a look at previous revisions of this gist. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dedent(text) { | |
var re_whitespace = /^([ \t]*)(.*)\n/gm; | |
var l, m, i; | |
while ((m = re_whitespace.exec(text)) !== null) { | |
if (!m[2]) continue; | |
if (l = m[1].length) { | |
i = (i !== undefined) ? Math.min(i, l) : l; | |
} else break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
/// | |
/// Very simple script to convert a normal JS module to a RequireJS-compatible | |
/// AMD module; intended for command-line usage, and integration into build | |
/// systems. | |
/// | |
/// Reads from stdin & writes to stdout; output can be piped to uglifyjs to | |
/// minify/compress the code. | |
/// | |
/// Examples: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// quite untested, adapted from BigstickCarpet's gist, attempt to make it simpler to use | |
function openIndexedDB (fileindex) { | |
// This works on all devices/browsers, and uses IndexedDBShim as a final fallback | |
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB; | |
var openDB = indexedDB.open("MyDatabase", 1); | |
openDB.onupgradeneeded = function() { | |
var db = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nltk | |
import gensim | |
sample="""Renewed fighting has broken out in South Sudan between forces loyal to the president and vice-president. A reporter in the capital, Juba, told the BBC gunfire and large explosions could be heard all over the city; he said heavy artillery was being used. More than 200 people are reported to have died in clashes since Friday. The latest violence came hours after the UN Security Council called on the warring factions to immediately stop the fighting. In a unanimous statement, the council condemned the violence "in the strongest terms" and expressed "particular shock and outrage" at attacks on UN sites. It also called for additional peacekeepers to be sent to South Sudan. | |
Chinese media say two Chinese UN peacekeepers have now died in Juba. Several other peacekeepers have been injured, as well as a number of civilians who have been caught in crossfire. The latest round of violence erupted when troops loyal to President Salva Kiir and first Vice-President Riek Machar began sho |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import heapq | |
from collections import defaultdict | |
class Graph: | |
def __init__(self, n): | |
self.nodes = set(range(n)) | |
self.edges = defaultdict(list) | |
self.distances = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* NameDisplay.js */ | |
import ReactPropTypes from 'prop-types'; | |
const NameDisplay = ({name}) => ( | |
<div> | |
<div> | |
First Name: {name.first} | |
</div> | |
<div> | |
Last Name: {name.last} |
OlderNewer