This file contains hidden or 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
| const calculatePages = (length: number, current: number, total: number) => { | |
| if (length === 0) return [] | |
| if (length === 1) return [current] | |
| if (total <= length + 4) return Array.from({ length: total }, (_v, i) => i + 1) | |
| const jumpSize = Math.ceil(length / 2) | |
| const centerStart = Math.min(Math.max(current - (length - jumpSize), 3), total - length - 1) | |
| const jumpStart = current <= length + 1 ? 2 : `-${jumpSize}` | |
| const jumpEnd = current >= total - length ? total - 1 : `+${jumpSize}` | |
| return [1, jumpStart, ...Array.from({ length }, (_v, i) => centerStart + i), jumpEnd, total] | |
| } |
This file contains hidden or 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
| // Defaults | |
| const defaultOptions = { | |
| format: 'image/png', | |
| quality: 0.92, | |
| width: undefined, | |
| height: undefined, | |
| Canvas: undefined | |
| } | |
| const createCanvas = options => (options.Canvas ? new options.Canvas() : window.document.createElement('canvas')) |
This file contains hidden or 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 convertTextToImage = (context, text, font = 'normal normal 24px cursive', color = '#000000') => { | |
| context.font = font | |
| context.fillStyle = color | |
| context.fillText(text, 0, 10) | |
| context.canvas.width = context.measureText(text).width | |
| return context.canvas.toDataURL() | |
| } |
This file contains hidden or 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 screenshot = (canvasRef, base, avatar) => { | |
| const ctx = canvasRef.getContext('2d') | |
| const imageObj1 = new Image() | |
| const imageObj2 = new Image() | |
| imageObj1.src = base.src | |
| imageObj1.onload = () => { | |
| ctx.drawImage(imageObj1, 0, 0, base.height, base.width) | |
| imageObj2.src = avatar.src | |
| imageObj2.onload = () => { | |
| ctx.drawImage(imageObj2, avatar.left, avatar.top, avatar.height, avatar.width) |
This file contains hidden or 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
| package main | |
| import ( | |
| "fmt" | |
| "math" | |
| ) | |
| const round = 1000000.0 | |
| func Sqrt(x float64) float64 { |
This file contains hidden or 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
| javascript:(()=>{const e=new Date,t=(e.getDate()+'').padStart(2,'0'),l=e.getMonth()+1;let n=`https://elron.pilet.ee/et/otsing/Tondi/Pääsküla/${`${e.getFullYear()}-${l}-${t}`}`;location.href=n})(); |
This file contains hidden or 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
| onKeydown(e) { | |
| const { toggleSidebar, next, previous } = this.props; | |
| const keyMapping = new Map([ | |
| [ 83, toggleSidebar ], // user presses the s button | |
| [ 37, next ], // user presses the right arrow | |
| [ 39, previous ] // user presses the left arrow | |
| ]); | |
| if (keyMapping.has(e.which)) { |
This file contains hidden or 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
| /** | |
| * Uses the Durstenfeld shuffle algorithm, | |
| * a modern optimized version of the Fisher-Yates | |
| * (aka Knuth) shuffle. | |
| * | |
| * http://en.wikipedia.org/wiki/Fisher-Yates_shuffle#The_modern_algorithm | |
| * | |
| * @param {Array} Array to shuffle | |
| * @return {Array} Shuffled array | |
| */ |
This file contains hidden or 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
| console.log('%c 👋 Salutations, hax0r.\nFeel free to look around. FYI, you\'ll have a better view of the code over at GitHub: \nhttps://github.com/andreasvirkus/cottage', 'background: #223; color: #bada55'); |
This file contains hidden or 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
| // Needs spread operator (... notation) | |
| export const promisify = (fn) => { | |
| return (...args) => { | |
| return new Promise((resolve, reject) => { | |
| fn(...args, (err, res) => { | |
| if (err) return reject(err) | |
| return resolve(res) | |
| }) | |
| }) | |
| } |