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 { throttle } from 'lodash' | |
import { useEffect, useRef, useState } from 'react' | |
export type DraggableProps = { | |
onMouseDown: (e: React.MouseEvent) => void | |
style: { top: number; left: number } | |
} | |
export default function useDraggable(): DraggableProps { | |
const [mouseDown, setMouseDown] = useState(false) |
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 { useEffect, useRef, useState } from 'react'; | |
/** | |
* This hook uses the browsers native lazy load functionality for images, if present. | |
* If not, it uses the IntersectionObserver as a fallback, and make sure the browser | |
* load the image when it is within 500px to the viewport. | |
* If the browser neither supports lazy loading of images, nor IntersectionObserver, it | |
* will fallback to just loading the image straight away. | |
* | |
* It is super-easy to use. Just spread the hook into the <img>-tag: |
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
/** | |
* Dette programmet sorterer varer på kolonial.no. | |
* Du må gå helt inn i en spesifikk kategori før du starter sorteringen. | |
* | |
* Kjør programmet ved å åpne opp utviklerverktøy, og lim koden inn i konsollet. | |
* Når du vil sortere en annen kategori senere, holder det å trykke "Pil opp" | |
* og så "Enter" for å sortere på nytt. | |
* | |
* ALL BRUK GJØRES PÅ EGET ANSVAR. Denne koden er med vilje IKKE gjort om til | |
* noen browser-plugin. Med en gang kolonial.no gjør kode-endringer kan dette |
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
/* | |
This is the most basic setup you need in express 4 for listening on POST and GET. | |
*/ | |
var express = require('express'); | |
var bodyParser = require('body-parser'); | |
var app = express(); |
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
/* Write out for months. */ | |
var dates = []; | |
$('.js-stream-item ._timestamp').each(function() { | |
dates.push(new Date($(this).data('time-ms'))); | |
}); | |
var data = {}; |
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 promiseNode(name, attributes) { | |
/** | |
* | |
*/ | |
return function (content, beforeInsideOrAfter) { | |
var start = '<' + name; | |
var end = '</' + name + '>'; |
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
window.setInterval(function() { | |
var levelColors = [], m = Math; | |
function getLevelColor(level) { | |
if(levelColors[level] === undefined) { | |
levelColors[level] = (m.PI * m.random()).toString(16).slice(-2); | |
} | |
return levelColors[level]; | |
} |
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
/** | |
* Detects whether the PDF.js Chromium extension is installed in the browser. | |
* Example: isPDFJSExtensionInstalled(function(result) { alert('Is PDF.js installed? ' + result);}); | |
* | |
* @param {function(boolean)} callback - Called when the detection completed. | |
* | |
* Author: Rob Wu <rob@robwu.nl> (https://robwu.nl) | |
* | |
* Made synchronous by a handwaiving Lebbe | |
* |
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($, callback) { | |
if($) { | |
callback(); | |
return; | |
} | |
var script = document.createElement('script'); | |
script.src = '//code.jquery.com/jquery-1.11.1.min.js'; | |
script.onload = callback; | |
document.getElementsByTagName('body')[0].appendChild(script); | |
})(window['jQuery'], function() { |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="test.har"></script> | |
<script type="text/javascript"> | |
// Insert "var test = " at the very beginning of the HAR-file | |
var entries = test.log.entries; |