Skip to content

Instantly share code, notes, and snippets.

@dannvix
dannvix / electron-main.js
Created June 24, 2015 15:44
Create Electron's BrowserWindow with dynamic HTML content
// main.js for Electron
var app = require("app"),
BrowserWindow = require("browser-window");
app.on("window-all-closed", function() {
app.quit();
})
var mainWindow = null;
app.on("ready", function() {
@dannvix
dannvix / EtwEventStore.js
Last active August 29, 2015 14:21
Generic parser and store for ETW (Event Tracing for Windows)
var fs = require("fs");
var xml2js = require("xml2js"),
Lazy = require("Lazy"),
Papa = require("papaparse"),
moment = require("moment");
var Guid = require("./Guid"); // https://gist.github.com/dannvix/e1a93a3dda87cef7a60b
var EtwEventStore = (function() {
function EventsByType(store, type) {
this._store = store;
@dannvix
dannvix / Guid.js
Last active August 29, 2015 14:21
var Guid = (function() {
function Guid(guid) {
var guid = guid || "";
guid = [].filter.call(guid.toLowerCase(), function(ch) {
return (ch >= "0") && (ch <= "f");
}).join("");
if (guid.length == 0) {
this._isNull = true;
guid = "000000000000000000000000000";
}
@dannvix
dannvix / CanvasFileSystem.html
Created May 12, 2015 15:04
Experiments on HTML 5 Canvas and File System APIs
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML 5 Canvas & File System</title>
<style>
button,
#canvas {
cursor: pointer;
}
@dannvix
dannvix / screenshot.js
Created April 12, 2015 10:08
Simply capture web-page screenshot with PhantomJS
#!/usr/bin/env phantom
var webpage = require("webpage"),
system = require("system");
var args = system.args;
if (args.length < 3) {
system.stderr.writeLine("usage: " + args[0] + " <URL> <Filename.png> [delay] [viewWidth] [viewHeight]");
phantom.exit();
}
@dannvix
dannvix / bitset.js
Last active August 29, 2015 14:17
Very simple bitset operations in JavaScript
/* bitset.js
*
* bitset = new Bitset(64);
* bitset.toString(); // "0000000000000000000000000000000000000000000000000000000000000000"
* bitset.setBit(48, 1).setBit(23, 1).setBit(52, 1);
* bitset.toString(); // "0000000000010001000000000000000000000000100000000000000000000000"
* bitset.toInt(); // 4785074612469760
*
* bitset.fromInt(679642164705874);
* bitset.toString(); // "0000000000000010011010100010000110000101110011010011101001010010"
@dannvix
dannvix / member_function_reflection.cpp
Last active August 29, 2015 14:16
SFINAE test for specific member function using C++11
#include <iostream>
#include <type_traits>
class Foo {
public:
int ToString();
};
class Bar {
public:
@dannvix
dannvix / ext_id.cpp
Last active August 29, 2015 14:15
Clang 3.3+ supports extended identifiers
// clang++ hello.cpp
#include <iostream>
template <typename lhs_t, typename rhs_t>
inline int operator, (lhs_t lhs, rhs_t b) {
std::cout << "飲冰室茶集" << std::endl;
return 0;
}
template <typename lhs_t, typename rhs_t>
#include <iostream>
template <typename lhs_t, typename func_t>
inline func_t operator > (lhs_t const &lhs, func_t rhs) {
return rhs;
}
template <typename rhs_t, typename func_t>
inline auto operator < (func_t const &lhs, rhs_t const &rhs) -> decltype(lhs())
{
@dannvix
dannvix / BypassPTTOver18.user.js
Last active November 13, 2017 01:07
自動跳過 PTT 的分級檢查 (請謹慎使用)
// ==UserScript==
// @name Bypass PTT Over-18 Checking
// @description 自動跳過 PTT 的分級檢查 (請謹慎使用)
// @namespace https://www.ptt.cc/bbs
// @author Shao-Chung Chen
// @license MIT (http://opensource.org/licenses/MIT)
// @version 1.1.0
// @include http://www.ptt.cc/*
// @include https://www.ptt.cc/*
//