Skip to content

Instantly share code, notes, and snippets.

@ploxiln
ploxiln / utf8_test.c
Last active September 29, 2017 19:00
my utf-8 coding test for software engineering job applicants
/*************************************************************************************************
UTF-8 validation test
UTF-8 is used for encoding text, which means, mapping the bytes in a file to meaningful characters.
ASCII is the classic, once ubiquitous encoding in the western world. It uses a single byte per
character, and uses only the lower 7 bits of that byte. It can only represent the characters on a
US keyboard (as well as tab and carriage return etc). Other encodings exist which also use a single
byte per character, but use all 8 bits, like ISO-8859-1, or use multible bytes per character, like
UCS-32 which always uses 4 bytes per character. These encodings can represent many more characters,
such as accented ones.
// nodejs script to compare npm-shrinkwrap files
// TODO check errors with files and report nicely
var fs = require('fs');
var path = require('path');
function usage() {
console.log("USAGE: %s %s (--needs-delete|--compare)"
+ " <actual-shrinkwrap-file> <target-shrinkwrap-file>",
path.basename(process.argv[0]), path.basename(process.argv[1]) );
import java.util.Arrays;
import java.util.Comparator;
class EvenFirst implements Comparator<Integer> {
public int compare(Integer a, Integer b) {
return a % 2 - b % 2;
}
}
public class SortTest {
@ploxiln
ploxiln / daemonize.sh
Last active August 29, 2015 14:10
simple way to daemonize a server process as a normal user
#!/bin/bash
rails s </dev/null >>rails.log 2>&1 &
disown $!
# to stop, use "pkill rails"
#!/bin/bash
# This uses linux "transport control" aka tc to affect OUTGOING packets.
# For more information about "netem", the network emulation module, see:
# http://www.linuxfoundation.org/collaborate/workgroups/networking/netem
# http://lartc.org/howto/index.html section 9 and 12.
usage() {
echo "USAGE: $(basename $0) --interface=<ethX> (--dport=<PORT> | --host=<IP>) (--delay=<DELAY_SPEC> | --loss=<LOSS_SPEC>) --start"
echo " $(basename $0) --interface=<ethX> (--stop | --status)"
@ploxiln
ploxiln / README.md
Last active November 6, 2018 06:31
nsq_http_consumer

nsq_http_consumer

Provides an http interface to nsq consumers.

NOTE: This has not updated since before nsqio/pynsq#117 "nsq.Reader.disabled() no longer effective" was fixed.

nsqd already provides an http interface to nsq publishers - just POST data to /put?topic=$TOPIC, typically to the nsqd running locally,

Keybase proof

I hereby claim:

  • I am ploxiln on github.
  • I am ploxiln (https://keybase.io/ploxiln) on keybase.
  • I have a public key ASBuXt0Bz7WxQl9CtCURyVlCPSn59-kT6xpk9ufP6KLbhgo

To claim this, I am signing this object:

@ploxiln
ploxiln / getjslibs.sh
Created May 17, 2017 19:44
getjslibs.sh
#!/bin/sh
set -eu
cd $(dirname $0)
DESTDIR="static/js"
mkdir -p $DESTDIR
JQUERY_VER="3.2.1"
JQUERY_SHA1="fd81582bf1b15e6747472df880ca822c362a97d1"
JQUERY_URL="https://code.jquery.com/jquery-${JQUERY_VER}.js"
#!/bin/sh
set -eu
RTSP_URL=
RTSP_AUTH=
TRANSPORT=tcp
TLS_OPTS=
WITH_AUDIO=false
WITH_VIDEO=true
WITH_RTCP=false
import logging
import tracemalloc
from tornado.web import RequestHandler, HTTPError
class MemTraceHandler(RequestHandler):
def post(self) -> None:
action = self.get_argument('action')
nframe = self.get_argument('nframe', "6")