Skip to content

Instantly share code, notes, and snippets.

View huobazi's full-sized avatar
🎯
Focusing

Marble Wu huobazi

🎯
Focusing
View GitHub Profile
@huobazi
huobazi / install-golang.sh
Created October 30, 2017 16:45
Install golang
# install golang
GOREL=go1.7.3.linux-amd64.tar.gz
wget https://storage.googleapis.com/golang/$GOREL
tar xfz $GOREL
mv go /usr/local/go
rm -f $GOREL
PATH=$PATH:/usr/local/go/bin
echo 'PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
@huobazi
huobazi / installvagrant
Last active October 30, 2017 03:27 — forked from rrgrs/installvagrant
installs brew, virtualbox, and vagrant in osx
if ! type "brew" > /dev/null; then
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)";
fi
brew tap phinze/homebrew-cask && brew install brew-cask;
brew cask install virtualbox;
brew cask install vagrant;
brew cask install vagrant-manager;
@huobazi
huobazi / description.markdown
Created February 15, 2017 04:37 — forked from runemadsen/description.markdown
Reverse polymorphic associations in Rails

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.

@huobazi
huobazi / zepto_or_jquery_getUrlParam.js
Created June 29, 2016 10:30
Zepto or jQuery getUrlParam
$.fn.getUrlParam = function(j) {
var l = new RegExp("(^|&)" + j + "=([^&]*)(&|$)");
var k = window.location.search.substr(1).match(l);
if (k != null) {
if (/^[\u4e00-\u9fa5]+$/.test(decodeURIComponent(k[2]))) {
return k[2];
} else {
return $("<div/>").text(k[2]).html();
}
}
@huobazi
huobazi / README.md
Created June 29, 2016 09:43 — forked from mimosa/README.md
微信扫码登录。
  1. 判定是否在微信中打开
def wechat?
    request.user_agent =~ /MicroMessenger/i 
end
  1. 分别调用 微信网页扫码公众号授权
@huobazi
huobazi / HtmlHelperExtensions.cs
Created May 23, 2016 08:05 — forked from mariusschulz/HtmlHelperExtensions.cs
Two C# extension methods for inlining script and style bundles into the HTML response using ASP.NET MVC and the System.Web.Optimization framework.
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
public static class HtmlHelperExtensions
{
public static IHtmlString InlineScripts(this HtmlHelper htmlHelper, string bundleVirtualPath)
{
return htmlHelper.InlineBundle(bundleVirtualPath, htmlTagName: "script");
@huobazi
huobazi / eav.sql
Created April 24, 2016 07:56 — forked from vwood/eav.sql
EAV in postgres
-- Entity Attribute Value Model in Postgres
CREATE TABLE public.entity (
id serial NOT NULL,
type varchar(25) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE public.defined_attributes (
key varchar(25) NOT NULL,
-- clean up database from previous test
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
-- create EAV tables
CREATE TABLE entity (
id SERIAL PRIMARY KEY,
name TEXT,
description TEXT
);
@huobazi
huobazi / js-get-fn-name.js
Created April 20, 2016 08:31 — forked from dfkaye/js-get-fn-name.js
get a javascript function name
function getFnName(fn) {
var f = typeof fn == 'function';
var s = f && ((fn.name && ['', fn.name]) || fn.toString().match(/function ([^\(]+)/));
return (!f && 'not a function') || (s && s[1] || 'anonymous');
}
console.log(getFnName(String)); // 'String'
console.log(getFnName(function test(){})); // 'test'
console.log(getFnName(function (){})); // 'anonymous'
@huobazi
huobazi / ubuntu apt-get aliyun镜像源.md
Created April 15, 2016 09:38 — forked from nibocn/ubuntu apt-get aliyun镜像源.md
ubuntu apt-get aliyun镜像源

trusty(14.04)

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse