Skip to content

Instantly share code, notes, and snippets.

View mpr0xy's full-sized avatar

mpr0xy mpr0xy

  • ChengDu China
View GitHub Profile
@mpr0xy
mpr0xy / getDaysInWeek.js
Created August 7, 2024 03:15
Get the date data for a certain month and organize it by week
function getDaysInWeek(year, month) {
function getDaysInMonth(year, month) {
return new Date(year, month, 0).getDate();
}
const monthDays = getDaysInMonth(year, month);
console.log(monthDays);
let startDate = 1;
const results = [];
while (startDate <= monthDays) {
const week = [0, 0, 0, 0, 0, 0, 0];
@mpr0xy
mpr0xy / getScrollTop.js
Created November 29, 2023 03:56
latest7daysMasteredWordsCountByDay
function getScrollTop() {
var scroll_top = 0
if (document.documentElement && document.documentElement.scrollTop) {
scroll_top = document.documentElement.scrollTop
} else if (document.body) {
scroll_top = document.body.scrollTop
}
return scroll_top
}
@mpr0xy
mpr0xy / rotateMatrix.js
Created November 3, 2023 03:22
矩阵旋转,可用在俄罗斯方块变换方块形状上
const rotate = function (matrix, direction) {
for (let y = 0; y < matrix.length; ++y) {
for (let x = 0; x < y; ++x) {
[matrix[x][y], matrix[y][x]] = [matrix[y][x], matrix[x][y]];
}
}
if (direction === 'clockWise') {
// 顺时针旋转
matrix.forEach((row) => row.reverse());
} else {
@mpr0xy
mpr0xy / use_ffmpeg_to_combine_video_and_subtitles.js
Created February 13, 2023 01:34
批量合并视频和字幕
const path = require("path");
const { execSync } = require("child_process");
const fs = require("fs");
const makeNewMkv = (dirPath, mkvPath, assPath) => {
const mkvName = path.basename(mkvPath).match(/S[\d]{2}E[\d]{2}/)[0];
console.log("mkvName", mkvName);
if (fs.existsSync(path.resolve(dirPath, mkvName + ".mkv"))) {
console.log(`${mkvName}已存在`);
return;
function ip(str) {
var length = str.length;
var ans = 0;
var stack = [];
var step = 0;
var lastStep = 0;
var lastchar = ''
// 处理每一次位移
function handle() {
function ip(str) {
var length = str.length;
var ans = [];
var stack = [];
var step = 0;
var lastStep = 0;
var lastchar = ''
// 生成原始数组
for (var i = 0; i < 32; i++) {
@mpr0xy
mpr0xy / drag-drop-upload-unzip.js
Created May 31, 2016 04:09 — forked from iwek/drag-drop-upload-unzip.js
Drag and Drop, Upload and Unzip
/* Drag'n drop stuff */
var drag = document.getElementById("drag");
drag.ondragover = function(e) {e.preventDefault()}
drag.ondrop = function(e) {
e.preventDefault();
var length = e.dataTransfer.items.length;
for (var i = 0; i < length; i++) {
var entry = e.dataTransfer.items[i].webkitGetAsEntry();
var file = e.dataTransfer.files[i];
@mpr0xy
mpr0xy / gist:6037ceeca4c8ba0458ee
Created August 14, 2015 01:56
抽时间了解
graphql,Postgres,graphql-relay-js,前端: relay
@mpr0xy
mpr0xy / mp-gulp-img-src.js
Last active August 29, 2015 14:25
mp-gulp-img-src
var through = require('through2');
module.exports = function() {
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new gutil.PluginError('gulp-mp-upai-upload', 'Streaming not supported'));
@mpr0xy
mpr0xy / parseFile.js
Created June 8, 2014 03:48
解析一个md文件前面加入得一些描述信息(比如写一篇博客会包含得信息)
var fs = require('fs');
var yamlish = require('yamlish'); // npm install yamlish
// md文件头部类似下面的注释信息,为了不会于文章里的注释符号冲突,加了>>
// 第一行需要时空行,因为yamlish库是从第二行开始解析得,你妹啊
/*<<