You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could not find gem 'guard-bundler (>= 0) ruby' in the gems available on this machine.
Run bundle install to install missing gems.
$ bundle --help
Could not find gem 'guard-bundler (>= 0) ruby' in the gems available on this machine.
Run bundle install to install missing gems.
#query as association mod coutUser.find_by_sql("SELECT COUNT(*) FROM `users` INNER JOIN \(select user_id, count(*) from authorizations where 1=1 group by user_id HAVING count(*)>1) a \ON a.`user_id` = `users`.`id`")User.find_by_sql(" SELECT COUNT(*) user_auth_count, users.* FROM `users` INNER JOIN `authorizations` ON `authorizations`.`user_id` = `users`.`id`group by user_id HAVING count(*)>1")#这个查找出来的只有有authorizations关联的用户User.joins(:authorizations).where("(authorizations.provider != 'mmbkoo') and users.id >= #{s_user.id}").limit(250)#这里查找的就是所有非mmbk用户并且id大于s_user的id的5个用户User.where("id >= #{s_user.id} and id NOT IN (SELECT authorizations.user_id FROM authorizations WHERE (provider = 'mmbkoo'))").limit(5)
the monitor for mysql
sudo apt-get install mytop
mytop -uroot -proot
Mongoid Dynamic fields
classPersonincludeMongoid::Documentfield:first_name,type: String#field :middle_name, type: String#field :last_name, type: Stringend# Set the person's gender to male.person[:gender]="Male"person.gender="Male"# Get the person's gender.person.gender# Raise a NoMethodError if value isn't set.person.genderperson.gender="Male"# Retrieve a dynamic field safely.person[:gender]person.read_attribute(:gender)# Write a dynamic field safely.person[:gender]="Male"person.write_attribute(:gender,"Male")# and you can use create to pass all Fields and dynamic you wantPerson.create(first_name: "111",password: "xxxx",dy_field: "asdfa")
数据查询
# 过滤 -> 排序 -> limit
criteria = GxUser.where({:UserID => {"$nin" => exclude_users}, :UserName => {"$ne" =>""}, :HeadImage => {"$ne" => nil}, :Status =>"1", :IsOnline =>"1"}
### mysql nest transaction
- [Nested+transactions](http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html#module-ActiveRecord::Transactions::ClassMethods-label-Nested+transactions)
mysql 子事务 `ActiveRecord::Rollback` exception in the nested block does not issue a ROLLBACK, In order to get a ROLLBACK for
the nested transaction you may ask for a real sub-transaction by passing requires_new: true. If anything goes wrong, the
database rolls back to the beginning of the sub-transaction without rolling back the parent transaction.
但是 child transaction 不会 触发 parent transaction 的 ROLLBACK。因此需要依据 child transaction 的 exec result to detected should parent transaction rollback
Now lets fire up Gedit and turn on our preferences.
To get to our plugins go to Edit > Preferences > Plugins.
We’re going to enable the following options:
Snippets
Code Comment
Embedded Terminal
Find in Files
Rails Extract Partial
Rails File Loader
Session Saver (Optional)
Smart Indent (Optional)
Tab Switch (Optional)
TextMate Style AutoCompletion
tips for gedit multi edit mod plugin
The new plugin introduces a new ‘mode’ in which you can do multi editing. You enter this mode by Ctrl+Shift+C, and once enabled you can start inserting edit points manually by pressing Ctrl+E at any point in the document. Additionally, you can use Ctrl+Home and Ctrl+End to respectively insert edit points at the beginning or end of the line automatically (it will also skip to the previous/next line so you can quickly insert edit points at the beginning or end of some lines). When you start typing the inserts/deletes will be replicated in all the edit points. You can then press Escape to remove the additional edit points, and press Escape again to finally quit multi edit mode.
removing selected commit log entries for a repository
# If you want to keep your work and just 'undo' that commit command (you caught before pushing to repo):
git reset --soft HEAD~1
# move HEAD to A, but leave the index and working tree as for D
git reset --soft <SHA1-for-A>
# Redo the D commit re-using the commit message, but now on top of A
git commit -C <SHA1-for-D>
# Re-apply everything from the old D onwards onto this new place
git rebase --onto HEAD <SHA1-for-D> master
#Or, you could look at the output of git log, find the commit id of the commit you want to back up to, and then do this:
git reset --hard <sha1-commit-id>
git pull --rebase
git pull --rebase just does:
git fetch
git rebase
Because branch merges in git are recorded with a merge commit, they are supposed to be meaningful—for example, to indicate when a feature has been merged to a release branch. However, during a regular daily workflow where several team members sync a single branch often, the timeline gets polluted with unnecessary micro-merges on regular git pull. Rebasing ensures that the commits are always re-applied so that the history stays linear.
You can configure certain branches to always do this without the --rebase flag:
#make 'git pull' on master always use rebase
$ git config branch.master.rebase true
You can also set up a global option to set the last property for every new tracked branch:
# setup rebase for every tracking branch
$ git config --global branch.autosetuprebase always
Make sure all folders "behind" your mountpoints are empty. Out of experience i'd say most probably you hide some data behind a mountpoint.
you can check what is in the folder behind the mountpoint without having to unmount the disk/partitions (which can be nice if for example you would have to unmount /usr). Just do a
# mount --bind / /mnt
# du -shx /mnt
also as a side note:
# du -shx /
does the same as your du... but is quite a bit shorter (-s stands for summarize)
ncdu -x /
mount /dev/xvda2 /mnt/check_disk_xvda2/
ncdu /mnt/check_disk_xvda2/
# remove file mark as deleted but, process which use it not quit
lsof |grep deleted
kill -s QUIT 11878
kill -9 11878
du - estimate file space usage
SYNOPSIS
du [OPTION]... [FILE]...
du [OPTION]... --files0-from=F
DESCRIPTION
Summarize disk usage of each FILE, recursively for directories.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
write counts for all files, not just directories
--apparent-size
print apparent sizes, rather than disk usage; although the apparent size is usually smaller, it may be larger due to holes in (`sparse') files, internal fragmentation, indirect blocks, and the like -B, --block-size=SIZE scale sizes by SIZE before printing them. E.g., `-BM' prints sizes in units of 1,048,576 bytes. See SIZE format below. -b, --bytes equivalent to `--apparent-size --block-size=1' -c, --total produce a grand total -D, --dereference-args dereference only symlinks that are listed on the command line --files0-from=F summarize disk usage of the NUL-terminated file names specified in file F; If F is - then read names from standard input -H equivalent to --dereference-args (-D) -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G) --si like -h, but use powers of 1000 not 1024 -k like --block-size=1K -l, --count-links count sizes many times if hard linked -m like --block-size=1M -L, --dereference dereference all symbolic links -P, --no-dereference don't follow any symbolic links (this is the default)
-0, --null
end each output line with 0 byte rather than newline
-S, --separate-dirs
do not include size of subdirectories
-s, --summarize
display only a total for each argument
-x, --one-file-system
skip directories on different file systems
-X, --exclude-from=FILE
exclude files that match any pattern in FILE
--exclude=PATTERN
exclude files that match PATTERN
-d, --max-depth=N
print the total for a directory (or file, with --all) only if it is N or fewer levels below the command line argument; --max-depth=0 is the same as --summa‐
rize
--time show time of the last modification of any file in the directory, or any of its subdirectories
--time=WORD
show time as WORD instead of modification time: atime, access, use, ctime or status
--time-style=STYLE
show times using style STYLE: full-iso, long-iso, iso, +FORMAT FORMAT is interpreted like `date' --help display this help and exit --version output version information and exit Display values are in units of the first available SIZE from --block-size, and the DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables. Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set). SIZE may be (or may be an integer optionally followed by) one of following: KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.
LVM 是一个应用于 Linux 内核的本地卷管理器 (Logical Volume Manager)。 使用 LVM 你可以抽象你的存储空间,并且可以有很容易更改的“虚拟分区”。LVM的基本模块如下:
Physical volume (PV): 物理卷,例如一个硬盘,或一个Software RAID设备; 硬盘的一个分区 (或者甚至硬盘本身或者回环文件),在它上面可以建立卷组。It has a special header and is divided into physical extents. Think of physical volumes as big building blocks which can be used to build your hard drive.
Volume group (VG): 卷组,将一组物理卷收集为一个管理单元;Group of physical volumes that are used as storage volume (as one disk). They contain logical volumes. Think of volume groups as hard drives.
Logical volume(LV): 逻辑卷,等同于传统分区,可看作便准的块设备,以容纳文件系统;A "virtual/logical partition" that resides in a volume group and is composed of physical extents. Think of logical volumes as normal partiti
Shop.limit(1).map(&:products).map(&:count)Shop.joins(:products).select("shops.*, COUNT(products.id) as products_count").group("shops.id").first.products_count
# not goodcode=[]code << "next line of code #{something}"code << "another line #{some_included_expression}"code.join("\n")
# goodcode=%{First line second lineThird line #{2 + 2}}
code=<<CODE# End-of-heredoc must be at the start a line var1 = "foo" var2 = "bar"CODE# good# End-of-heredoc may be preceeded by whitespacecode=<<-CODEvar1 = "foo"var2 = "bar" CODE
Passes each element of the collection to the given block. The method returns true if the block never returns false or nil.
if the block is not given, Ruby adds an implicit block of {|obj| obj} (that is all? will return true only if none of the collection members are false or nil.)
Passes each element of the collection to the given block. The method returns true if the block ever returns a value other than false or nil. If the block is not given, Ruby adds an implicit block of {|obj| obj} (that is any? will return true if at least one of the collection members is not false or nil.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
during use ubuntu, you must done some wrong thing, and you do not konw how to back, or can't understander what it's mean ...
the best method is restore or reset, ubuntu-deskdop or unity ...
three tips:
sudo spt-get remove --purge ubuntu-desktop;sudo apt-get install ubuntu-desktop;sudo reboot;
sudo apt-get remove --purge unity;sudo apt-get install unity;reboot;# if you unity have some incorrent setting, you can
sudo apt-get install myunity
#then type
myunity
classHashmoduleClassMethodsdefself.replace_key(old_key,new_key)self[new_key]=self[old_key]self.delete(new_key)endendendh.keys.eachdo |key|
h[new_keys[key]]=h[key]# add entry for new keyk.delete(key)# remove old keyend
find ./app -type f | xargs sed -i 's/person_notes_path/notes_person_path/g'
find ./app/controllers/ -type f ! -path '*.rb'
find ./app/ -type f -path '*.js' -o -path "*.coffee"cd /source-dir
find . -name .snapshot -prune -o \(\! -name *~ -print0 \)|
cpio -pmd0 /dest-dir
This command copies the contents of /source-dir to /dest-dir, but omits
files and directories named .snapshot (and anything in them). It also
omits files or directories whose name ends in~, but not their con‐
tents. The construct -prune -o \( ... -print0 \) is quite common. The
idea here is that the expression before -prune matches things which are
to be pruned. However, the -prune action itself returns true, so the
following -o ensures that the right hand side is evaluated only for
those directories which didn't get pruned (the contents of the pruned directories are not even visited, so their contents are irrelevant). The expression on the right hand side of the -o is in parentheses only for clarity. It emphasises that the -print0 action takes place only for things that didn't have -prune applied to them. Because the
default `and' condition between tests binds more tightly than -o, this is the default anyway, but the parentheses help to show what is going on.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ImproperlyConfigured: Error importing middleware django.middleware.csrf: "No module named csrf"
Seems it's due to django version http://stackoverflow.com/questions/2341030/no-module-named-csrf
I'm currently using 1.1.2 django version
(I may post enhancement issue, but is there a way to freeze django binnaries in the project in order to have a standalone & plug and play django-mumble?)