Skip to content

Instantly share code, notes, and snippets.

View BoZhuM's full-sized avatar

bo.zhu BoZhuM

  • shenzhen, guangdong, china
View GitHub Profile
@BoZhuM
BoZhuM / binary_tree.rb
Last active November 11, 2017 09:56
ruby BinaryTree implemention
# https://www.cs.cmu.edu/~adamchik/15-121/lectures/Trees/trees.html
module BinaryTree
class Node
attr_accessor :value, :left, :right, :parent
def initialize(v, parent = nil)
@value = v
@left = EmptyNode.new(self)
@right = EmptyNode.new(self)
@parent = parent
end
@BoZhuM
BoZhuM / nested_attributes_uniqueness_validator.rb
Created November 2, 2016 13:01 — forked from artemv/nested_attributes_uniqueness_validator.rb
Uniqueness validator for has_many associated items with accepts_nested_attributes_for
class NestedAttributesUniquenessValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
value = value.reject(&:_destroy) # let's ignore the items to be destroyed here
unless value.map(&options[:field]).uniq.size == value.size
record.errors[attribute] << "must be unique"
duplicates = value - Hash[value.map{|obj| [obj[options[:field]], obj]}].values
duplicates.each { |obj| obj.errors[options[:field]] << "has already been taken" }
end
end
end
@BoZhuM
BoZhuM / a-modern-frontend-dev.md
Created January 25, 2016 15:05 — forked from dwayne/a-modern-frontend-dev.md
Articles, tutorials and tools for modern front-end development.

Problem: What does a Modern Front-End Development Workflow Look Like?

I want to start writing libraries and large applications using the JavaScript language. However, I don't know how to setup the project and which build tools to use. What I do know is that the JavaScript community has moved way beyond using browser developer tool plugins and strategically-placed console.log() statements to debug, test, and build code.

I need help.

Below, I will keep track of articles, tutorials and tools I come across as I search for a way to bring my front-end development chops up-to-date.

The Ultimate Resource

@BoZhuM
BoZhuM / index.html
Created September 29, 2015 02:03
jbVpJo
<body>
<div class="container">
<div class='row'>
<div class='col-md-3 col-sm-3 col-xs-3 text-center text-success'>
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-shopping-cart fa-stack-1x fa-inverse"></i>
</span>
<p>hello1</p>
</div>
@BoZhuM
BoZhuM / .vimrc
Created September 24, 2015 07:45
if !isdirectory($HOME."/.vim/bundle/Vundle.vim")
silent !mkdir -p ~/.vim/bundle
silent !git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
endif
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
@BoZhuM
BoZhuM / .vimrc
Last active September 21, 2015 10:17
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
@BoZhuM
BoZhuM / cvimrc
Created September 16, 2015 01:47
" Settings
set nohud
set nosmoothscroll
set noautofocus " The opposite of autofocus; this setting stops
" sites from focusing on an input box when they load
set typelinkhints
let searchlimit = 30
let scrollstep = 70
let barposition = "bottom"
@BoZhuM
BoZhuM / si.rb
Created August 23, 2014 07:10 — forked from rasefon/si.rb
require 'RMagick'
$scale_size = 256.0
$img_fn1 = ARGV[0]
$img_fn2 = ARGV[1]
$scale_size = ARGV[2].to_f if ARGV[2]
def calculate_threshold(img_fn)
dir_name = File.dirname(img_fn)
-- (p - 1) / (t + 2)^1.5
CREATE FUNCTION SP_POINTS(P SMALLINT(5), CREATED TIMESTAMP)
RETURNS TINYINT(3)
RETURN (P - 1) / POW(TIMESTAMPDIFF(HOUR, CREATED, NOW()) + 2, 1.5);
@BoZhuM
BoZhuM / IE-hack
Created February 28, 2014 05:57
IE hack
selector{
property:value; /* 所有浏览器 */
property:value9; /* 所有IE浏览器 */
+property:value; /* IE7 */
_property:value; /* IE6 */
}