Skip to content

Instantly share code, notes, and snippets.

@Rplus
Rplus / Spread Operator.md
Created February 6, 2017 18:12
6 Great Uses of the Spread Operator, via: https://davidwalsh.name/spread-operator

Calling Functions without Apply

function doStuff (x, y, z) { }
var args = [0, 1, 2];
doStuff(...args);
function doStuff(x, y, z) {}
var args = [0, 1, 2];
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script>
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(function(position) {
{
"1": 0.094,
"1.5": 0.135137432,
"2": 0.16639787,
"2.5": 0.192650919,
"3": 0.21573247,
"3.5": 0.236572661,
"4": 0.25572005,
"4.5": 0.273530381,
"5": 0.29024988,
@Rplus
Rplus / isBackwards.js
Last active November 25, 2016 10:23
detection for the direction of selecting text
// ref: http://stackoverflow.com/a/16265811
// 用 createRange 創一新的選擇範圍來判斷圈選的方向性
// anchorNode 是開頭圈選的 node, focusNode 是停止圈的位置
// 當圈選起始點在後面,那這個生成的 range 會壓縮成一個疊合的位置,`range.toString()` 時會變成空字串 ''
// 不過我這邊調整了一下,直接輸出 rg.collapsed 比較原生,不用再轉一次 `toString()`
function isBackwards (sel) {
var rg = document.createRange();
rg.setStart(sel.anchorNode, sel.anchorOffset);
rg.setEnd(sel.focusNode, sel.focusOffset);
return rg.collapsed;
{
"pokemon": {
"1": {
"name": "Bulbasaur",
"types": [
"grass",
"poison"
],
"cpPerUpgrade": 13.5,
"evolveCost": "25",
@Rplus
Rplus / highlight-low-pr.js
Last active September 26, 2016 17:39
PokeNurse's custom script
console.log(123);
let pokeInfo = [
{
"id": 150,
"name": "Mewtwo",
"type": "psychic",
"cpPerLv": 60,
"maxcp": 4144
},
{
[
{
"id": 150,
"name": "Mewtwo",
"type": "psychic",
"cpPerLv": 60,
"maxcp": 4144
},
{
"id": 149,
@Rplus
Rplus / a.js
Created July 25, 2016 16:32 — forked from FremyCompany/a.js
Namespaces events without jQuery
// once in the headers
defineMetaEvent('Namespace','Click');
// then when you need it
document.body.onNamespaceClick.add(function(e) { /*...*/ });
document.body.onNamespaceClick.clear();
@Rplus
Rplus / demo.html
Created July 18, 2016 03:03
<noscript> with staticmap img
<div id="map-container" class="side-content">
<div id="map-content" data-lat=25.0327429 data-lng=121.5668311 style="width:620px; height: 400px;" class="map-wrapper">
</div>
</div>
<!-- then… -->
<div id="map-container" class="side-content">
<div id="map-content" data-lat=25.0327429 data-lng=121.5668311 style="width:620px; height: 400px;" class="map-wrapper">
<noscript>
<img src="https://maps.googleapis.com/maps/api/staticmap?center=25.0327429,121.5668311&zoom=16&size=620x400&markers=25.0327429,121.5668311">
@Rplus
Rplus / README.md
Last active July 3, 2016 14:51
[Codepen] Rocket in Space