Skip to content

Instantly share code, notes, and snippets.

View justdoit0823's full-sized avatar

余森彬 justdoit0823

View GitHub Profile
@justdoit0823
justdoit0823 / equality_or_assign_expression.md
Created September 4, 2017 02:51
All different versions of equality or assign expression.

javascript version

(function equality_or_assign(){
  a = 0;
  if(a = 1) console.log('assign', a);
  else console.log('equality');
})();
@justdoit0823
justdoit0823 / extract_task_arguments.js
Created September 6, 2017 09:49
Extract task arguments from celery flower html.
function extract_task_arguments(n){
task_table = document.getElementById('tasks-table');
for(var i = 1; i < n + 1; i++) console.log(task_table.childNodes[3].childNodes[i].childNodes[3].childNodes[0].data + "\t" + task_table.childNodes[3].childNodes[i].childNodes[4].childNodes[0].data)
}
@justdoit0823
justdoit0823 / files_in_thread.sh
Created September 7, 2017 09:27
List opened files within threads of processes.
lsof -aK -p pid
@justdoit0823
justdoit0823 / The-evolution-of-coroutine-in-Python.md
Created September 9, 2017 13:29
The evolution of coroutine in Python.

Coroutine

In wikipedia website, coroutine is defined as followed.

Coroutines are computer-program components that generalize subroutines for non-preemptive multitasking, by allowing multiple entry points for suspending and resuming execution at certain locations. Coroutines are well-suited for implementing familiar program components such as cooperative tasks, exceptions, event loops, iterators, infinite lists and pipes.

In early Python, coroutine is not natively supported, but only generator which supports yielding and resuming. Normal generators are just used to return value one by one, rather than yielding to different other generators as cooperative tasks. There are two main methods, send and throw resume generator's execution with specified value or exception. Afterwards in some frameworks, such as Tornado, the generator is used to implement framework level coroutine like tornado.gen.coroutine. However in ea

@justdoit0823
justdoit0823 / manipulate_string.sh
Created September 11, 2017 08:55
How to manipulate string in bash.
# initialize string array
FILES=(aaa bbb ccc)
# retrive array's all elements
for file in `${FILES[@]}`
do
echo $file
@justdoit0823
justdoit0823 / nginx_tips
Created September 12, 2017 08:12
A collection of nginx tips.
rewrite url prefix
rewrite /url_prefix(.*) /$1 break;
@justdoit0823
justdoit0823 / inspect-descriptor.c
Last active September 16, 2017 04:27
Inspect the internal implementations of descriptor in CPython.
#include "Python.h"
PyTypeObject * create_type(const char * name){
PyObject * args, * dict, * value;
PyTypeObject * type;
args = PyTuple_New(3);
PyTuple_SetItem(args, 0, PyUnicode_FromString(name));
@justdoit0823
justdoit0823 / inspect_multithread.sh
Last active February 27, 2018 09:31
How to debug multithread program under linux system?
# get processes with related threads
ps -eLf |grep "process name"
# list all opened file descriptors in a process PID and under which thread
lsof -aKp PID
# trace syscalls in a process's main thread or other thread PID
strace -p PID
@justdoit0823
justdoit0823 / future.rst
Created September 25, 2017 12:47
Celery future concurrency document.

Concurrency with Future

Introduction

@justdoit0823
justdoit0823 / project_condition.yml
Created September 28, 2017 08:52
Manage multiple projects witnin one playbook in ansible.
---
- name: "common task"
command: "{{item.cmd}}"
with_items:
- {cmd: "A", tag: ["projectA"]}
- {cmd: "B", tag: ["projectB"]}
when: item.tag | intersect(current_tag)
tags:
- projectA