Skip to content

Instantly share code, notes, and snippets.

@oscarkuo
oscarkuo / ReadSqliteTableColumns.cs
Created December 12, 2015 07:26
Read SQLite table columns
using System;
using System.Collections.Generic;
using System.Data.SQLite;
namespace Sqlite3ToJson
{
class Program
{
static void Execute(string connectionString, string sql, Action<SQLiteDataReader> action)
{
@oscarkuo
oscarkuo / SQLiteTableToJson.cs
Created December 12, 2015 19:46
Convert a SQLite table to a JSON file
using System;
using System.Data.SQLite;
using System.IO;
using System.Text;
using Newtonsoft.Json;
namespace Sqlite3ToJson
{
class Program
@oscarkuo
oscarkuo / circularlayout.html
Created December 30, 2015 07:26
Circular layout HTML elements
<html>
<head>
<style>
.container {
width:400px;
height:400px;
float:left;
position:relative;
background:#ccc;
overflow:hidden;
const _ = require('lodash');
const assert = require('assert');
const rotate = (value, max, min) => {
const distance = max - min + 1;
if (value > max) {
return min + ((value - max - 1) % distance);
} else if (value < min) {
return max - ((min - value - 1) % distance);
@oscarkuo
oscarkuo / switch-to-gdm.sh
Last active April 13, 2016 18:05
Switch to GDM
# CTRL+ALT+F2 to another console and then
sudo pacman -Syu
sudo pacman -S gdm
sudo systemctl disable lightdm
sudo systemctl enable gdm
sudo systemctl stop lightdm
sudo systemctl start gdm
@oscarkuo
oscarkuo / socketio-145-disconnect-client-from-server.js
Created April 19, 2016 02:52
Disconnect Socket.IO client from server (v1.4.5)
var nsp = io.of('/conn');
nsp.on('connection').on('authenticated', (socket) => {
socket.on('triggerDisconnect', (d) => {
if (nsp.connected[socket.id]) {
nsp.connected[socket.id].disconnect();
}
});
});
@oscarkuo
oscarkuo / promise-retry.js
Last active April 21, 2016 02:08
Promise retry
'use strict';
let i = 0;
const fn = () => {
if (i++ < 5)
throw new Error(`crap ${i}`);
return "success";
};
@oscarkuo
oscarkuo / node-bad-ssl-test.js
Last active April 22, 2016 01:41
Bypass bad SSL check in Node request
// npm i request-promise
// node node-bad-ssl-test.js
const rp = require('request-promise');
const url = 'https://self-signed.badssl.com';
const r1 = rp.get(url, { rejectUnauthorized: true });
r1.then((body) => {
@echo off
set cassie_running=0
set creeper_running=0
set roguecode_running=0
call:stopVmIfItIsRunning "roguecode" roguecode_running
call:stopVmIfItIsRunning "creeper" creeper_running
call:stopVmIfItIsRunning "cassie" cassie_running
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
let fs = require('fs');
let mw = require('nodemw');
let count = 0;
let client = new mw({
protocol: "http",
server: 'en.wikipedia.org',
path: '/w',
debug: false