Skip to content

Instantly share code, notes, and snippets.

View aprilandjan's full-sized avatar
👻
wandering

May aprilandjan

👻
wandering
View GitHub Profile
@pmuellr
pmuellr / cpu-percent.js
Created April 12, 2016 14:59
get CPU usage percent for a process in node, using proposed `process.cpuUsage()` function
'use strict'
// see: https://github.com/nodejs/node/pull/6157
var startTime = process.hrtime()
var startUsage = process.cpuUsage()
// spin the CPU for 500 milliseconds
var now = Date.now()
while (Date.now() - now < 500)
@tzutalin
tzutalin / timer-c++03.cpp
Last active March 11, 2023 12:25 — forked from gongzhitaao/CppTimer.md
Simple high resolution timer in C++
#include <iostream>
#include <ctime>
class Timer
{
public:
Timer() { clock_gettime(CLOCK_REALTIME, &beg_); }
double elapsed() {
clock_gettime(CLOCK_REALTIME, &end_);
@parmentf
parmentf / GitCommitEmoji.md
Last active April 30, 2024 17:34
Git Commit message Emoji
@ufologist
ufologist / autoplay-audio-ios.html
Created December 3, 2015 03:55
在 iOS 微信浏览器中自动播放 HTML5 audio(音乐) 的正确方式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>Auto play html audio in iOS WeChat InAppBrowser the right way</title>
</head>
<body>
<h1>在 iOS 微信浏览器中自动播放 HTML5 audio(音乐) 的正确方式</h1>
<p>核心原理: 在微信的JS-API 中 play 一下 audio 即可达到自动播放的目的(应该是微信自己做了处理)</p>
@bzdgn
bzdgn / GenerateDummyCode.java
Last active April 8, 2024 13:36
Dummy Code Generator : 10000 Lines of Useless Code
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class GenerateDummyCode {
public static void main(String[] args) {
String className = "Eben";
String newLine = "\n";
String tab = "\t";
String classStart = "public class " + className + " {";
String closeBracket = "}";
@ghinda
ghinda / object-to-form-data.js
Last active March 30, 2024 18:51
JavaScript Object to FormData, with support for nested objects, arrays and File objects. Includes Angular.js usage.
// takes a {} object and returns a FormData object
var objectToFormData = function(obj, form, namespace) {
var fd = form || new FormData();
var formKey;
for(var property in obj) {
if(obj.hasOwnProperty(property)) {
if(namespace) {
@soheilhy
soheilhy / nginxproxy.md
Last active March 22, 2024 08:54
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

#include <unistd.h>
#include <node.h>
#include <string.h>
#include <v8.h>
using namespace v8;
unsigned long long count = 0;
// native blocking/compute intensive function
@branneman
branneman / better-nodejs-require-paths.md
Last active April 27, 2024 04:16
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions