Skip to content

Instantly share code, notes, and snippets.

View garywu's full-sized avatar
🌴
On vacation

Gary Wu garywu

🌴
On vacation
View GitHub Profile
<?php
function cidr_match($ip, $ranges)
{
$ranges = (array)$ranges;
foreach($ranges as $range) {
list($subnet, $mask) = explode('/', $range);
if((ip2long($ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($subnet)) {
return true;
}
}
---
# ^^^ YAML documents must begin with the document separator "---"
#
#### Example docblock, I like to put a descriptive comment at the top of my
#### playbooks.
#
# Overview: Playbook to bootstrap a new host for configuration management.
# Applies to: production
# Description:
# Ensures that a host is configured for management with Ansible.
@garywu
garywu / gist:8c84dbb9e16b0f2967fd
Last active August 29, 2015 14:04
Indepensible Open Source Softwares
@garywu
garywu / 0_reuse_code.js
Created January 11, 2014 18:54
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
// Chrome extension 'content scripts' run in a sandboxed 'isolated world'
// (http://code.google.com/chrome/extensions/content_scripts.html#execution-environment).
// However, there are ways to get out and execute js code in the page
// context. Google searching revealed the following ways:
////////////////////////////////////////////////////////////////////////////////
// http://blog.afterthedeadline.com/2010/05/14/how-to-jump-through-hoops-and-make-a-chrome-extension/
// it looks like jQuery must be loaded by the content-script
jQuery('body').append('<script type="text/javascript">(function(l) {
var res = document.createElement('SCRIPT');

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@garywu
garywu / ipython_0.13.2_windows_line_profiler.md
Last active February 21, 2018 00:58
How to fix ipython 0.13.2 runtime Error on Windows: ImportError: No module named line_profiler

How to fix: ImportError: No module named line_profiler when running ipython 0.13.2 on Windows

  1. install Line_profiler from http://www.lfd.uci.edu/~gohlke/pythonlibs/
  2. This should install following files in your python27/Lib/site-packages directory
    • _line_profiler.pyd
    • line_profiler-1.0b3-py2.7-win32.egg
    • line_profiler-1.0b3-py2.7.egg-info
    • line_profiler.py
    • line_profiler.pyc
  • line_profiler.pyo