Skip to content

Instantly share code, notes, and snippets.

import struct
import SocketServer
from base64 import b64encode
from hashlib import sha1
from mimetools import Message
from StringIO import StringIO
class WebSocketsHandler(SocketServer.StreamRequestHandler):
magic = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
@duydao
duydao / Readme.md
Last active September 4, 2016 22:46
java_home wrapper for Mac OS X, adding support for jenv

java_home wrapper for Mac OS X, adding support for jenv

this script checks if a (global) version was set by jenv. if so, use that path if no version was requested explicitly (e.g. by java_home -v '1.7.*' or something)

# set env if not already done so. something like this for bash
echo "export JAVA_HOME=`/usr/libexec/java_home`" >> ~/.bash_profile;

# this should be brew install something, but for now...
#!/usr/bin/env python2
# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford ([email protected])
# The author disclaims copyright to this source code.
import sys
import struct
import socket
import time
import select
$ echo "* text=auto" >>.gitattributes
$ rm .git/index # Remove the index to force Git to
$ git reset # re-scan the working directory
$ git status # Show files that will be normalized
$ git add -u
$ git add .gitattributes
$ git commit -m "Introduce end-of-line normalization"
@duydao
duydao / extension.ts
Created December 28, 2016 00:14
vscode cmd+d plugin
'use strict';
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
let disposable = vscode.commands.registerCommand('extension.sublime.cmd_d', () => {
let editor = vscode.window.activeTextEditor;
if ( !editor ) {
return;
};
@duydao
duydao / uri.js
Created January 7, 2017 11:08 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@duydao
duydao / demo.json
Last active February 20, 2018 09:39
For demo
[
{"name": "Button 1", "url": "", "method": "GET"},
{"name": "Button 2", "url": "", "method": "GET"},
{"name": "Button 3", "url": "", "method": "GET"},
{"name": "Button 4", "url": "", "method": "GET"},
{"name": "Button 5", "url": "", "method": "GET"},
{"name": "Button 6", "url": "", "method": "GET"},
{"name": "Button 7", "url": "", "method": "GET"},
{"name": "Button 8", "url": "", "method": "GET"},
{"name": "Button 9", "url": "", "method": "GET"},
@duydao
duydao / word-service.py
Created February 19, 2018 10:57 — forked from randidwiputra/word-service.py
Flask + gensim word2vec
from gensim.models import word2vec
import logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
model1 = word2vec.Word2Vec.load_word2vec_format('models/glove_model.txt', binary=False)
model1.init_sims(replace=True)
from flask import Flask, jsonify, request
app = Flask(__name__)