Skip to content

Instantly share code, notes, and snippets.

@zhangtaihao
zhangtaihao / zsh-nvmrc.plugin.zsh
Created June 6, 2022 01:15
Auto activate .nvmrc for oh-my-zsh
# Track currently active .nvmrc file.
ZSH_NVMRC_ACTIVE=""
autoload -U add-zsh-hook
load-nvmrc() {
# Ignore missing nvm (e.g. wrong load order).
if ! command -v nvm &> /dev/null; then
return
fi
from argparse import ArgumentParser
__all__ = ['execute', 'metacommand', 'command', 'argument']
_reserved_args = 'func', 'command'
_default_registry = {}
def execute(args, prog=None, commands=None):
@zhangtaihao
zhangtaihao / app-data-feed.txt
Last active August 12, 2018 14:01
Data feed algorithm
get :: retrieveCache || retrieveUpdate => data
update :: retrieveUpdate => data
subscribe(s :: data => {}) :: <addSubscriber>(s) + (retrieveCache => data) && s(data) + refresh
unsubscribe(s) :: <removeSubscriber>(s)
refresh :: !retrieveCache && retrieveUpdate ~~~> <subscribed> && refresh
retrieveCache :: !<expired> && fetchCache => data
retrieveUpdate :: <debounce>(fetchRemote || fetchCache || fetchInitial) => data
fetchCache :: loadCache => data || <error>
@zhangtaihao
zhangtaihao / init-project-js.sh
Last active August 13, 2018 07:15
Init JS project with Airbnb style guide
#!/bin/sh
DEFAULT_GITIGNORE='.idea\nnode_modules'
DEFAULT_ESLINTIGNORE='node_modules'
DEFAULT_ESLINTRC='{"parser":"babel-eslint","extends":"airbnb","plugins":["prefer-object-spread"],"rules":{"prefer-object-spread/prefer-object-spread":2}}'
DEFAULT_BABELRC='{"presets":["env"]}'
git init
npm init -y
npm i -D babel-eslint eslint-plugin-prefer-object-spread jest babel-jest
@zhangtaihao
zhangtaihao / mysqltmpfs
Created August 30, 2012 02:44
Debian init script to set up MySQL data on tmpfs
#!/bin/sh
### BEGIN INIT INFO
# Provides: mysqltmpfs
# Required-Start: $local_fs $remote_fs $syslog
# Required-Stop: $local_fs $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Start-Before: mysql
# X-Stop-After: mysql
### END INIT INFO
@zhangtaihao
zhangtaihao / gist:3088645
Created July 11, 2012 07:13
Remove content_taxonomy_allowed_values()
module_load_include('inc', 'field', 'field.crud');
$fields = field_read_fields(array('type' => 'taxonomy_term_reference'));
foreach ($fields as $field) {
if (isset($field['settings']['options_list_callback']) && $field['settings']['options_list_callback'] == 'content_taxonomy_allowed_values') {
$field['settings']['options_list_callback'] = 'taxonomy_allowed_values';
field_update_field($field);
}
}
Use this script to archive a specific release of the project. This script exports a git project with a specific object (e.g. tag), adds version information to the module <code>*.info</code> files and packages the project into properly named archive.
To start using the script, download the script and place it in the parent directory of your git project folders. For security reasons, the uploaded script below is named as a text file. If desired, the script can be renamed.
<h3>Usage</h3>
<kbd>export-project [-D &lt;output_dir&gt;] [-C &lt;working_dir&gt;] [-z|-g] [-x &lt;ext&gt;]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[-N] [-P] [-A|-F &lt;url&gt;] &lt;project&gt; &lt;tree-ish&gt; [&lt;version&gt;]</kbd>
<h4>Arguments</h4>
@zhangtaihao
zhangtaihao / gist:668604
Created November 9, 2010 01:57
Drupal: map content_taxonomy field vocabulary settings to core taxonomy node type configuration
$nodes = array();
foreach (content_fields() as $field_key => $field) {
if (strpos($field['module'], 'content_taxonomy') === 0) {
$type = $field['type_name'];
$nodes[$field['vid']][$field_key] = $type;
}
}
module_load_include('inc', 'taxonomy', 'taxonomy.admin');
foreach ($nodes as $vid => $types) {
$vocabulary = (array) taxonomy_vocabulary_load($vid);