Skip to content

Instantly share code, notes, and snippets.

@goctave
goctave / gist:ec28fbdd48cd0f7f477a4761fdeec08c
Created December 12, 2016 02:05 — forked from methane/gist:2185380
Tornado Example: Delegating an blocking task to a worker thread pool from an asynchronous request handler
from time import sleep
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.web import Application, asynchronous, RequestHandler
from multiprocessing.pool import ThreadPool
_workers = ThreadPool(10)
def run_background(func, callback, args=(), kwds={}):
def _callback(result):
@goctave
goctave / main.cpp
Created May 9, 2012 03:11
CareerCup_4.3@1point3acres
//
// main.cpp
// cc4_3
//
// Created by gsw on 12-5-9.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
/******************************************************************************
* Given a sorted (increasing order) array, write an algorithm to create a
@goctave
goctave / main.cpp
Created May 6, 2012 02:43
CareerCup_4.1@1point3acres
/*****************************************************************
Implement a function to check if a tree is balanced
For the purposes of this question, a balanced tree is
defined to be a tree such that no two leaf Nodes differ
in distance from the root by more than one
******************************************************************/
#include <iostream>
@goctave
goctave / main.cpp
Created May 3, 2012 03:58
CareerCup_3.3@1point3acres
//
// main.cpp
// cc3_3
//
// Created by kandia on 12-5-3.
// Copyright (c) 2012年 kandia. All rights reserved.
//
/*******************************************************************************
* Imagine a (literal) stack of plates If the stack gets too high, it might
@goctave
goctave / 2_3.cpp
Created April 26, 2012 02:44
CareerCup_2.3@1point3acres
#include <iostream>
using namespace std;
struct node
{
int data;
node *next;
node(): data(0), next(NULL){}
};
@goctave
goctave / 2_1.cpp
Created April 24, 2012 03:15
CareerCup_2.1&2.2@1point3acres
/**********************************************************************
1.Write code to remove duplicates from an unsorted linked list
FOLLOW UP
How would you solve this problem if a temporary buffer is not allowed?
2.Implement an algorithm to find the nth to last element of
a singly linked list. (method: find_n())
***********************************************************************/
@goctave
goctave / 7.cpp
Created April 22, 2012 05:08
CareerCup_1.7@1point3acres
/*********************************************************************
Write an algorithm such that if an element in an MxN matrix is 0,
its entire row and column is set to 0
**********************************************************************/
#include <iostream>
using namespace std;
const int M = 4, N = 4;
@goctave
goctave / 6.cpp
Created April 21, 2012 06:56
CareerCup_1.6@1point3acres
/*
Q: Given an image represented by an NxN matrix,
where each pixel in the image is 4 bytes, write
a method to rotate the image by 90 degrees
Can you do this in place?
*/
/*
C++传递二维数组比较麻烦
@goctave
goctave / 5.cpp
Created April 20, 2012 05:41
CareerCup_1.5@1point3acres
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
void replace(char *str)
{
int n = 0;
int i;
for(i = 0; str[i] != '\0'; i++)
@goctave
goctave / 4.c
Created April 19, 2012 02:40
CareerCup_1.4@1point3acres
#include <iostream>
#include <string>
using namespace std;
bool is_anagram(const string &str1, const string &str2)
{
if(str1.size() != str2.size())
return false;
int cnt1[256] = {0};
int cnt2[256] = {0};