Skip to content

Instantly share code, notes, and snippets.

@justforuse
justforuse / copyToClipboard.js
Created December 3, 2020 06:45
copy string to your clipboard by javascript
function copyToClipboard(str) {
if (!str) {
return;
}
// input element cannot keep '\n', so you can turn to textarea
const inputEl = document.createElement('textarea');
inputEl.value = str;
inputEl.style.cssText = 'position: absolute; top: -9999px; left: -9999px;';
document.body.appendChild(inputEl);
inputEl.select();
@justforuse
justforuse / text.css
Created December 1, 2020 07:54
text ellipsis
.truncate {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
// your style, like max-width: 100px;
}
@justforuse
justforuse / a.js
Created October 21, 2020 09:53
JavaScript download canvas as image
const a = document.createElement('a');
const ele = document.querySelector('canvas');
a.download = 'img.png';
a.addEventListener('click', () => {
a.href = ele?.toDataURL("image/png");
})
a.click();
@justforuse
justforuse / URLSearchParams.js
Created October 13, 2020 13:26
Parse url search params by vanilla js
// Sometimes this should use location.href
let params = (new URL(document.location)).searchParams;
let name = params.get('name'); // is the string "Jonathan Smith".
let age = parseInt(params.get('age')); // is the number 18
@justforuse
justforuse / .gitignore
Created July 7, 2020 04:07 — forked from markbrouch/.gitignore
.gitignore file for front-end projects
# Created by https://www.gitignore.io/api/node,bower,osx,linux,windows,dropbox,sass,less,grunt,sublimetext,code
### Node ###
# Logs
logs
*.log
npm-debug.log*
# Runtime data
@justforuse
justforuse / eventemitter.js
Created May 4, 2020 13:56 — forked from mudge/eventemitter.js
A very simple EventEmitter in pure JavaScript (suitable for both node.js and browsers).
/* Polyfill indexOf. */
var indexOf;
if (typeof Array.prototype.indexOf === 'function') {
indexOf = function (haystack, needle) {
return haystack.indexOf(needle);
};
} else {
indexOf = function (haystack, needle) {
var i = 0, length = haystack.length, idx = -1, found = false;
@justforuse
justforuse / hair.md
Last active April 8, 2020 16:07
Maintain your hair

一、菠菜菠菜在生发食物10强排行榜中是一种非常有营养价值的食物,它不仅对人体健康有着不错的功效,而且经过专业的认证分析菠菜其中的铁、锌这两种微量元素能迅速的促进身体的代谢,在配合其中的维生素A和维生素B成分,在生发效果上绝对会是相当不错的。

二、牡蛎谈到牡蛎相信会让不少人咽一下口水,其实它在针对脱发生发的作用上是相当不错的,它其中丰富的锌成分能及时的给予人体充足的而营养,而且它能生发的功效也得到了临床的认证,所以经常食用一点牡蛎会有着不错的生发和滋润头发的效果哟!

三、粗粮经常听人们说五谷杂粮是最能给人体提供营养的食物之一了,所以它其中的生素B族和铜等成分不仅是日常提升营养的佳品,而且经常食用粗粮能很好的促进体内自身的代谢和调节,坚持食用一段时间能达到不错的生发效果。

四、坚果坚果一类的食物在营养价值上都是相当高的,而且很多的坚果中的营养成分都是人体所必备的,同时坚果中独特的成分能很好的调节人体激素,促进毛囊细胞的分化,据研究表明经常吃坚果不仅能生发,同时还能利于人体长寿哟!

@justforuse
justforuse / a.md
Created April 2, 2020 13:07
Regular expression trim string spaces
// leading and trailing
reg = /\S.*\S/

// trailing
reg = /.*\S/

// leading
reg = /\S.*/
@justforuse
justforuse / github.md
Created February 17, 2020 14:41
Github proxy when you can not access github

Add to your hosts

192.30.253.113    github.com
192.30.252.131 github.com
185.31.16.185 github.global.ssl.fastly.net
74.125.237.1 dl-ssl.google.com
173.194.127.200 groups.google.com
192.30.252.131 github.com
185.31.16.185 github.global.ssl.fastly.net
@justforuse
justforuse / fire.md
Last active January 15, 2020 06:12
Save your code in one command in case of fire

How to quick save your code and upload to remote server in case of fire

Git version

  • Code

fire.sh

branch_name=`git config user.name`
git add .