Skip to content

Instantly share code, notes, and snippets.

View huruji's full-sized avatar
☂️
被社会毒打的频率奇高

忽如寄 huruji

☂️
被社会毒打的频率奇高
View GitHub Profile
@huruji
huruji / gist:2d26f4d18436e43fbd8092fe5b0e2a49
Last active December 20, 2021 06:34 — forked from hyg/gist:9c4afcd91fe24316cbf0
在golang中打开浏览器
func openbrowser(url string) {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
@huruji
huruji / ex1
Created October 6, 2021 19:13 — forked from Quby/ex1
libuv example, timers and mkdir
#include "./../deps/libuv/include/uv.h"
#include <stdio.h>
int msg;
void mkdir_cb (uv_fs_t* req) {
int* msg = req->data;
printf("send(%d)\n", *msg);
}
@huruji
huruji / binding.gyp
Created October 6, 2021 18:01 — forked from bellbind/binding.gyp
[nodejs]Native module with libuv and v8::Promise on node-4
# -*- mode: python -*-
{
"targets": [
{
"include_dirs": ["<!(node -e \"require('nan')\")"],
"target_name": "TimerAndPromise",
"sources": [
"timer-and-promise.cc"
],
"conditions": [
@huruji
huruji / hello-world.cc
Created October 6, 2021 17:01 — forked from tejom/hello-world.cc
console.log v8
// Copyright 2015 the V8 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.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fstream>
#include <iostream>
@huruji
huruji / confirm.go
Created June 29, 2021 17:14 — forked from albrow/confirm.go
Go (golang): How to ask for user confirmation via command line
import (
"fmt"
"log"
"os"
"sort"
)
// askForConfirmation uses Scanln to parse user input. A user must type in "yes" or "no" and
// then press enter. It has fuzzy matching, so "y", "Y", "yes", "YES", and "Yes" all count as
// confirmations. If the input is not recognized, it will ask again. The function does not return
@huruji
huruji / cloudSettings
Last active June 2, 2020 10:42
code_settings_2020
{"lastUpload":"2020-06-02T09:16:19.677Z","extensionVersion":"v3.4.3"}
@huruji
huruji / install_pipenv.sh
Created February 23, 2020 18:37 — forked from samredai/install_pipenv.sh
Python: Solution to 'Pipenv: Command Not Found' After 'pip install pipenv'
sudo -H pip install -U pipenv
# If you did a user install because you do not have sudo access, you have to modify your path to add your user folder
# The command on the next line tells you where your user folder is
# python3 -m site --user-base
PYTHON_BIN_PATH="$(python3 -m site --user-base)/bin"
PATH="$PATH:$PYTHON_BIN_PATH"
@huruji
huruji / async-foreach.js
Created April 30, 2019 08:08 — forked from Atinux/async-foreach.js
JavaScript: async/await with forEach()
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)
@huruji
huruji / reset.js
Created February 23, 2019 07:57 — forked from 19h/reset.js
Node.js — Clear Terminal / Console. Reset to initial state.
console.reset = function () {
return process.stdout.write('\033c');
}
@huruji
huruji / validator-proxy.js
Last active October 8, 2018 18:17
A simple fluent validator using Proxy
var proxyContext = function(ctx) {
return new Proxy(ctx, {
get(obj, prop) {
if (prop in obj) {
return obj[prop];
}
const newCtx = proxyContext(ctx.clone());
if (prop in rules) {
let re = newCtx.addRule(rules[prop]);
return re;