Skip to content

Instantly share code, notes, and snippets.

View fiefdx's full-sized avatar

Haitao Yang fiefdx

View GitHub Profile
@fiefdx
fiefdx / nodejs-tcp-example.js
Last active March 29, 2019 07:28 — forked from tedmiston/nodejs-tcp-example.js
Node.js TCP client and server example
/*
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp
server, but for some reason omit a client connecting to it. I added an
example at the bottom.
Save the following server in example.js:
*/
var net = require('net');
@fiefdx
fiefdx / buffer.js
Created April 3, 2019 07:41 — forked from miguelmota/buffer.js
Node.js Buffer to ArrayBuffer
// @credit: http://stackoverflow.com/questions/8609289/convert-a-binary-nodejs-buffer-to-javascript-arraybuffer
// From Buffer to ArrayBuffer:
function toArrayBuffer(buffer) {
var ab = new ArrayBuffer(buffer.length);
var view = new Uint8Array(ab);
for (var i = 0; i < buffer.length; ++i) {
view[i] = buffer[i];
}
@fiefdx
fiefdx / node-event-loop-demo.js
Created April 12, 2019 02:07 — forked from ghaiklor/node-event-loop-demo.js
This example shows how you can block event loop in NodeJS
'use strict';
// The purpose of this example is to show
// how you can block the event loop with JavaScript.
// There is 3 routes
// / respond with Hello, World text
// /block uses JavaScript while for 5 seconds
// /non-block uses setTimeout for 5 seconds
// Do the following
@fiefdx
fiefdx / streamuploader.py
Last active May 5, 2019 06:49 — forked from alex8224/streamuploader.py
A multipart form parse for tornado
#!/usr/bin/env python
#-*-coding:utf-8 -*-
#
#Author: alex alex8224 at gmail.com
#Create by:2015-08-11 15:50:21
#Last modified:2015-10-10 09:19:05
#Filename:server.py
#Description:
from __future__ import absolute_import
import os
@fiefdx
fiefdx / README.md
Created September 17, 2019 02:53 — forked from mattsears/README.md
Gittr: A Git key/value store

Gittr.rb

Git as a key-value store! Build with Grit, it supports SET, GET, KEYS, and DELETE operations. In addition, we can also get the change history of key/values.

And since it's Git, we can easily enhance it to include other awesome Git features such as branches, diffs, reverting, and more!

Example:

@fiefdx
fiefdx / virtualenv_execute.py
Created December 24, 2019 09:56 — forked from turicas/virtualenv_execute.py
Execute Python code in a virtualenv, return its stdout and stderr
#!/usr/bin/env python
# coding: utf-8
import os
import shlex
from subprocess import Popen, PIPE
def execute_in_virtualenv(virtualenv_name, commands):
'''Execute Python code in a virtualenv, return its stdout and stderr.'''
@fiefdx
fiefdx / raspbian-python3.5.rst
Created January 5, 2020 02:46 — forked from BMeu/raspbian-python3.5.rst
Installing Python 3.5 on Raspbian

Installing Python 3.5 on Raspbian

As of October 2016, Raspbian does not yet include the latest Python release, Python 3.5. This means we will have to build it ourselves, and here is how to do it.

  1. Install the required build-tools (some might already be installed on your system).
@fiefdx
fiefdx / gist:de5df9d21734bcf89a49a969dcfa9780
Created November 27, 2020 16:20 — forked from 2-718/gist:712288
Generating SSH keys (OSX)

Generate ssh public keypair

$ cd ~/.ssh
$ ssh-keygen -t rsa -C "EMAIL"
Filename: EMAIL
Passphrase: choose appropriate passphrase
$ ssh-add EMAIL

Enable ssh-agent

$ ssh-agent bash

$ ssh-add ~/.ssh/id_rsa

@fiefdx
fiefdx / recursive_dictionary.py
Created March 2, 2021 06:46 — forked from Xjs/recursive_dictionary.py
a recursive updating dictionary in Python
# recursive_dictionary.py
# Created 2009-05-20 by Jannis Andrija Schnitzer.
#
# Copyright (c) 2009 Jannis Andrija Schnitzer
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
@fiefdx
fiefdx / opendiff.txt
Created April 12, 2021 09:49 — forked from kristofferh/opendiff.txt
Open FileMerge from command line
Open FileMerge from command line
opendiff
If the command-line doesn't work, and you have no /Developer directory anymore, you probably need to:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer