Skip to content

Instantly share code, notes, and snippets.

@elleryq
elleryq / gen_check_load_cmd.py
Created September 14, 2015 09:08
check_load command generator
#!/usr/bin/env python
# check_load is provied by nagios-plugins-basic
# The formula origin:
# * http://serverfault.com/questions/209566/what-warning-and-critical-values-to-use-for-check-load
import os
import sys
import multiprocessing
def main():
<?php namespace UnitTests;
// tests/TestCase.php
use Illuminate\Support\Facades\Artisan;
class TestCase extends \Illuminate\Foundation\Testing\TestCase
{
/**
* Creates the application.
@elleryq
elleryq / playbook.yml
Created September 3, 2015 09:09
Ansible playbook for test local_action
---
- hosts: all
tasks:
- name: Remote action test.
shell: cat /etc/hostname
register: rr
- debug: msg="{{rr.stdout}}"
- name: Local action test.
local_action: shell cat /etc/hostname
register: rr
@elleryq
elleryq / LibVirtManager.py
Created August 24, 2015 10:48
A simple libvirt wrapper.
import libvirt
class LibVirtManager(object):
def __init__(self, uri):
self.conn = libvirt.open(uri)
def createDomainFromXMLFile(self, xmlFile, flags):
"""
if the libvirt.VIR_DOMAIN_START_PAUSED flags is set, the guest
@elleryq
elleryq / get_stock_inf_from_capital.sh
Last active August 29, 2015 14:27
從群益權民最大網撈資料
#!/bin/bash
curl 'http://iwarrant.capital.com.tw/data/warrants/Get_wScreenerResultCont.aspx?wcodelist=036888,06506P,036662,06489P,035979,06354P,035347,05346P,06499P,035146,04813P,05973P,034019,05238P,06355P,033970,05489P,032748,035253,04814P,06051P,032154,035147,05584P,05609P,030854,034528,05525P,030443,034365&ndays_sv=60&_=1440129426372' -H 'Host: iwarrant.capital.com.tw' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0' -H 'Accept: */*' -H 'Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.5,en;q=0.3' --compressed -H 'X-Requested-With: XMLHttpRequest' -H 'Referer: http://iwarrant.capital.com.tw/warrants/wScreenerPull.aspx?ul=0050&ts=1440081747608' -H 'Cookie: ASP.NET_SessionId=g1ks0u45ylpceo3dv54bcz55' -H 'Connection: keep-alive' -o /tmp/output-big5.json
# the json is encoded with big5, convert it!
iconv -f big5 -t utf-8 -o /tmp/output.json /tmp/output-big5.json
# Please install 'jq' first: sudo apt-get install jq
# You can try filter syntax in https://jqplay.org
jq ".
@elleryq
elleryq / install_packer_image_into_kvm.sh
Created August 19, 2015 09:11
Create KVM domain with the image built by packer
#!/bin/bash
# Suppose that you had an image built by packer
# How to use it in KVM?
# Just use virt-install
virt-install --connect qemu:///system \
-n xmppdb \
-r 1024 \
--import \
--disk path=./packer-kvm.img,format=qcow2,size=10 \
--vnc \
@elleryq
elleryq / concurrent.futures-intro.md
Last active August 29, 2015 14:27 — forked from mangecoeur/concurrent.futures-intro.md
Easy parallel python with concurrent.futures

Easy parallel python with concurrent.futures

As of version 3.3, python includes the very promising concurrent.futures module, with elegant context managers for running tasks concurrently. Thanks to the simple and consistent interface you can use both threads and processes with minimal effort.

For most CPU bound tasks - anything that is heavy number crunching - you want your program to use all the CPUs in your PC. The simplest way to get a CPU bound task to run in parallel is to use the ProcessPoolExecutor, which will create enough sub-processes to keep all your CPUs busy.

We use the context manager thusly:

with concurrent.futures.ProcessPoolExecutor() as executor:
#!/bin/bash
# Copyright (c) 2011 Josh Schreuder
# http://www.postteenageliving.com
#
# 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
# furnished to do so, subject to the following conditions:

In ~/.atom/styles.less, add the below css setting

Windows

atom-text-editor {
  font-family: "Microsoft JhengHei", sans-serif;
  //font-size: 14px;
}
atom-pane {
 font-family: "Microsoft JhengHei", sans-serif;
@elleryq
elleryq / install.sh
Last active August 29, 2015 14:23 — forked from wdullaer/install.sh
# Ask for the user password
# Script only works if sudo caches the password for a few minutes
sudo true
# Add Docker PPA and install latest version
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
sudo apt-get update
sudo apt-get install lxc-docker -y