Skip to content

Instantly share code, notes, and snippets.

View madeinfree's full-sized avatar
🐱
Focusing

Whien_Liou madeinfree

🐱
Focusing
View GitHub Profile
const text = 'AACAAACAAC'
const pattern = 'AACAAC'
function indexOf(text, pattern) {
let index = -1
for (let i = 0; i < text.length; i++) {
for (let j = 0; j < pattern.length; j++) {
if (text[i + j] !== pattern[j]) {
break
}
@madeinfree
madeinfree / data.json
Last active October 31, 2019 08:40
如何驗證收到的非對稱加密訊息內容(明文)後,為原始的內容而非竄改過後呢?
{
"id": 1,
"name": "Whien",
"message": "Hello World"
}
const {
generateKeyPairSync,
createCipheriv,
createDecipheriv,
randomBytes,
createHash,
sign,
verify
} = require('crypto');
const { publicKey, privateKey } = generateKeyPairSync('ed25519', {
module.exports = {
generateMultipleInsertValues(data) {
return data.reduce((result, nextData, index) => {
result = result + Object.keys(nextData).reduce((values, key, keyIndex, allKeys) => {
if (keyIndex === 0) {
if (typeof nextData[key] === 'string') {
return values + `('${nextData[key]}', `
} else {
return values + `(${nextData[key]}, `
}
@madeinfree
madeinfree / declare-idleCallback.ts
Created February 12, 2019 04:47
declare IdleCallback
type RequestIdleCallbackHandle = any;
type RequestIdleCallbackOptions = {
timeout: number;
};
type RequestIdleCallbackDeadline = {
readonly didTimeout: boolean;
timeRemaining: (() => number);
};
declare global {
@madeinfree
madeinfree / index.html
Created September 23, 2018 02:42
use HTML5 MediaRecord API and SocketIO to build a simple voice room
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
@madeinfree
madeinfree / CreditCard.jsx
Created September 16, 2018 11:39
Rotate Credit Card for Reactjs
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
function CreditCard(props) {
return (
<div className="credit-card__wrapper">
<div
className={`animation credit-card__gray ${
/**
* 如果 (if)
* 就 {}
* 喊(1) console.log(1)
* 不然就 else {}
* 喊(2) console.log(2)
* parse: if(15 > 10) { console.log(1); } else { console.log(2); }
*/
const code = `如果 (15 > 10) 就 喊(1)`;
@madeinfree
madeinfree / babel-plugin-semantic-ui-react.js
Created September 2, 2018 13:53
Commonjs Semantic UI React Tree Shaking babel plugin
module.exports = function(babel) {
const { types: t } = babel;
const SingleTemplate = `semantic-ui-react/dist/commonjs/{{type}}/{{moduleName}}`;
const findTypeFolderToName = name => {
switch (name) {
case 'Grid':
case 'Breadcrumb':
case 'Form':
@madeinfree
madeinfree / what-forces-layout.md
Created August 15, 2018 11:43 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()