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
export default const splitn = (s, d, n = Infinity) => { | |
const a = s.split(d); | |
return [ | |
...a.slice(0, n - 1), | |
...(a.length >= n ? [a.slice(n - 1).join(d)] : []) | |
]; | |
}; |
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
export const repeat = (str, num) => `${Array(num + 1)}`.replaceAll(/,/g, str); | |
export const kebabCase = (string, delimiter = " ") => | |
string | |
.split(delimiter) | |
.map((word) => [ | |
`${Number.NEGATIVE_INFINITY}`.slice(0, 1)[0], | |
word.toLowerCase(), | |
]) | |
.flat() |
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 verses(bottles) { | |
const count = (b, cap) => `${b || `${cap ? 'N' : 'n'}o more`} bottle${b == 1 ? '' : 's'}`; | |
return [...new Array(bottles + 1)].map((v, i) => bottles - i).map(b => [ | |
`${count(b, true)} of beer on the wall, ${count(b)} of beer.`, | |
b > 0 | |
? `Take one down and pass it around, ${count(b - 1)} of beer on the wall.` | |
: `Go to the store and buy some more, ${count(bottles)} of beer on the wall.` | |
]); | |
} |
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
var getCaretYPosition = function(){ | |
var editor = CKEDITOR.instances.editor1, //get your CKEDITOR instance here | |
sel = editor.getSelection(), // text selection | |
obj = sel.getStartElement().$, // the element the selected text resides in | |
range = editor.getSelection().getRanges(), // range of selection | |
container = range[0].startContainer.$, // get the DOM node of the selected text, probably a textnode | |
textlen = typeof obj.textContent === "undefined" ? obj.innerText.length : obj.textContent.length, // get the length of the text in the container | |
offset = range[0].startOffset; // get the offset from the beginning of the text in the container to the caret | |
if (container.nodeType === 3) { // if the container is a text node | |
while (container.previousSibling) { // add the length of all the preceding text nodes and elements in the same parent element |
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
// Returns true about 50% of the time, false about 50% of the time. | |
export default const maybe = () => Math.random() < .5; | |
// This should be closer to .5 the more iterations you run. | |
export const tester = iterations => { | |
let yes = 0; | |
for (let i = 0; i < iterations; i++) maybe() && yes++; | |
return yes/iterations; | |
} |
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 titleSeach (title, archived) { | |
return fetch( | |
'/api/titlesearch.php?title=' + | |
encodeURIComponent(title) + | |
'&archived=' + | |
encodeURIComponent(JSON.stringify(archived)) | |
).then(res => { | |
if (!res.ok) return Promise.reject(res); | |
return res.json() | |
}); |
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
try { | |
const entities = await Nymph.getEntities( | |
{'class': BlogPost.class}, | |
{'type': '&', | |
'like': ['title', '%easy%'], | |
'equal': ['archived', false] | |
} | |
); | |
console.log(entities); | |
} catch (e) { |
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
<?php | |
/** | |
* Slim archiving class. | |
* | |
* Slim is a portable file archive format based on JSON. It can be self | |
* extracting in multiple languages. | |
* | |
* @license https://www.apache.org/licenses/LICENSE-2.0 | |
* @author Hunter Perrin <hperrin@gmail.com> |
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
export default function strRepeat (str, repeat) { | |
let curStr = str, i = 1, result = ''; | |
while (true) { | |
if (i & repeat) result += curStr; | |
i *= 2; | |
if (i >= repeat) break; | |
curStr += curStr; | |
} | |
return result; | |
} |
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
Array.prototype.insertInOrder = function(item) { | |
for (var i = 0; this[i] < item && i < this.length; i++); | |
this.splice(i, 0, item); | |
}; |
NewerOlder