This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo swapoff -a | |
sudo dd if=/dev/zero of=/swapfile bs=1G count=16 | |
sudo mkswap /swapfile | |
sudo swapon /swapfile | |
grep SwapTotal /proc/meminfo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C++ includes used for precompiling -*- C++ -*- | |
// Copyright (C) 2003-2013 Free Software Foundation, Inc. | |
// | |
// This file is part of the GNU ISO C++ Library. This library is free | |
// software; you can redistribute it and/or modify it under the | |
// terms of the GNU General Public License as published by the | |
// Free Software Foundation; either version 3, or (at your option) | |
// any later version. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseHandler(tornado.web.RequestHandler): | |
@tornado.gen.coroutine | |
def post_async(self, *args): | |
resp_dict = yield ioloop.IOLoop.current().run_in_executor(None, self.post_handler, args) | |
return resp_dict | |
@tornado.web.asynchronous | |
@tornado.gen.coroutine | |
def post(self, *args): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
import handlers as th | |
from tornado import web | |
class ErrorHandler(web.RequestHandler): | |
"""Generates an error response with status_code for all requests.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cp = require('child_process'); | |
const ec2 = function (callback) { | |
const URL = 'http://169.254.169.254/latest/meta-data/local-ipv4'; | |
// we make it silent and timeout to 1 sec | |
const args = [URL, '-s', '--max-time', '1']; | |
const opts = {}; | |
cp.execFile('curl', args, opts, (error, stdout) => { | |
if (error) return callback(new Error('ec2 ip error')); | |
else return callback(null, stdout); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
text = "oh-oh-oh c-c-c-c-come to home today c-c-c-c-come to me fine-tuning" | |
print(re.sub(r'(\w+(?:-))+(\w+)', '\\2', text)) | |
print(re.sub(r'(?<!\S)(\w{1,3})(?:-\1)*-(\w+)(?!\S)', '\\2', text)) | |
#pattern = r"(?<=-)\w+(?=[^-\w])" | |
pattern = r"(?<!\S)(\w{1,3})(?:-\1)*-(\w+)(?!\S)" | |
r = re.compile(pattern, flags=re.I | re.X | re.UNICODE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def longest_subsequence_bisect(seq, mode='strictly', order='increasing', | |
key=None, index=False): | |
""" | |
>>> longest_subsequence_bisect([1,2,3,4,5,6,7,2,2,2,2,2,5,1,7,8]) | |
Return the longest increasing subsequence of `seq`. | |
Parameters | |
---------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function scanDirStream(needle, params) { | |
var options = { | |
// find -type | |
type: 'f', | |
// find -name | |
name: '*', | |
limit: 100 | |
}; | |
for (var attrname in params) { options[attrname] = params[attrname]; } | |
return new Promise((resolve, reject) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export ICU_VERSION=63.1 | |
export PYICU_INCLUDES=/usr/local/Cellar/icu4c/63.1/include | |
export PYICU_LFLAGS=-L/usr/local/Cellar/icu4c/63.1/lib | |
export PYICU_CFLAGS=-std=c++11 | |
pip install pyicu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
async def demo(): | |
print("foo") | |
await asyncio.sleep(5) | |
return "bar" | |
def main(): | |
loop = asyncio.new_event_loop() | |
asyncio.set_event_loop(loop) | |
result = loop.run_until_complete(demo()) |