Skip to content

Instantly share code, notes, and snippets.

View sincerefly's full-sized avatar
😀
working...

Yieldone sincerefly

😀
working...
View GitHub Profile
@sincerefly
sincerefly / async-await.js
Created January 24, 2020 13:38 — forked from wesbos/async-await.js
Simple Async/Await Example
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works
const axios = require('axios'); // promised based requests - like fetch()
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}
<!DOCTYPE html>
<!--
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree.
-->
<html>
<head>
@sincerefly
sincerefly / headless.txt
Last active January 16, 2019 06:34
selenium vs puppeteer (chrome & Firefox) 打印网页标题
[dongdong@fedora29 headless-test]$ cat firefox-headless.py
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
driver.set_window_position(0, 0)
driver.set_window_size(1366, 768)
@sincerefly
sincerefly / async-retry.js
Created January 15, 2019 08:52
Async请求重试
// From: http://thecodebarbarian.com/common-async-await-design-patterns-in-node.js.html
const superagent = require('superagent');
const NUM_RETRIES = 3;
test();
async function test() {
let i;
@sincerefly
sincerefly / Promise.all和Async-Await
Created January 15, 2019 08:41
使用Async方式处理接受Promise结果可以省去then接收结果,更为方便
const bcrypt = require('bcrypt');
const NUM_SALT_ROUNDS = 8;
async function test() {
const pws = ["passwd", "passwd2", "passed3"];
const promises = pws.map(pw => bcrypt.hash(pw, NUM_SALT_ROUNDS));
const result = await Promise.all(promises);
console.log(result);
}
@sincerefly
sincerefly / index.html
Last active April 7, 2020 05:50
Electron文件拖拽与打开文件管理器选择文件路径,导出SQLite3数据库中的数据到Excel 运行效果与说明:https://blog.yasking.org/a/electron-drag-open-file-demo.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>数据导出工具 V1.0.2 </title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="date-select">
@sincerefly
sincerefly / copy_file.rs
Created September 20, 2017 06:56
复制文件,以时间戳为文件名
use std::fs;
use std::io;
use std::path::Path;
extern crate time;
fn timestamp() -> f64 {
let timespec = time::get_time();
// 1459440009.113178
let mills: f64 = timespec.sec as f64 + (timespec.nsec as f64 / 1000.0 / 1000.0 / 1000.0);
mills
@sincerefly
sincerefly / get_x3id.rs
Created September 12, 2017 01:49
rust include_bytes宏示例,加载DLL到EXE中,使用时解压出来调用,调用DLL并将DLL返回的信息复制到粘贴板
extern crate clipboard;
use clipboard::ClipboardProvider;
use clipboard::ClipboardContext;
extern crate libloading;
use libloading::{Library, Symbol};
use std::io::prelude::*;
use std::path::Path;
use std::ffi::CStr;
@sincerefly
sincerefly / global_flag.py
Created July 28, 2017 02:43
用于跨模块共享全局变量的包
import sys
class global_flag(object):
def __init__(self):
self.flag_value = False
def get(self):
return self.flag_value
def change(self):
self.flag_value = not self.flag_value
@sincerefly
sincerefly / record_bsdiff_memory.py
Created July 28, 2017 02:39
用于测试记录bsdiff内存占用的python脚本
#!/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division
from threading import Thread
import subprocess
import psutil
import time
import os