Skip to content

Instantly share code, notes, and snippets.

@xd547
xd547 / <bundle-name>-Prefix.pch
Created July 16, 2014 08:02
Add CoreData header to pch
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#endif
defaults write com.apple.finder AppleShowAllFiles TRUE
defaults write com.apple.finder AppleShowAllFiles FALSE
# Xcode
.DS_Store
*/build/*
xcuserdata
*.xccheckout
#CocoaPods
Pods
@xd547
xd547 / hello.go
Created March 19, 2014 13:53
Writing, building, installing, and testing Go code
# from https://www.youtube.com/watch?v=XCsL89YtqCs
mkdir gocode
export GOPATH=$HOME/gocode
cd gocode
mkdir -p src/github.com/xd547
mkdir hello
cd hello
# create hello.go
# see hello.go below
go install
@xd547
xd547 / gist:9641554
Created March 19, 2014 13:25
rails rspec controller json empty response.body
describe 'xxx' do
render_views
# ...
end
@xd547
xd547 / jquery_check_all.js
Created March 4, 2014 07:15
jQuery check all
$('#check_all').on('click', function() {
if ($(this).is(':checked')) {
$('input[id*="week"]').prop('checked', true);
} else {
$('input[id*="week"]').prop('checked', false);
}
});
$('input[id*="week"]').on('click', function() {
if ($('input:checked[id*="week"]').size() == $('input[id*="week"]').size()) {
@xd547
xd547 / jquery_object_compare.js
Created March 4, 2014 02:43
jQuery Object compare
// from http://stackoverflow.com/questions/2436966/how-would-you-compare-jquery-objects
// You need to compare the raw DOM elements, e.g.:
if ($(this).parent().get(0) === $('body').get(0))
// or
if ($(this).parent()[0] === $('body')[0])
function isLeapYear(year) {
var result = false;
var yearVal = parseInt(year);
if (yearVal % 100 == 0) {
if (yearVal % 400 == 0) {
result = true;
}
} else {
if (yearVal % 4 == 0) {
result = true;

I see this error when I try to suspend an Ubuntu 10 guest in Fusion:

The request to Suspend this virtual machine failed because the corresponding VMware Tools script did not run successfully.

If you have configured a custom suspend script in this virtual machine, make sure that it contains no errors. Attempting the operation again will ignore the script failure. You can also submit a support request to report this issue.

As the dialog states, the second time you try to suspend the VM it ignores the non-zero return code of the script and it seems to work. But it's annoying.

The problem appears to not be VMware actually, but Ubuntu (or Ubuntu's service script). I tried to figure out where exactly Ubuntu's initctl configuration/scripts is broken to no avail but found a work-around that I'm happy with.

@xd547
xd547 / validates.rb
Created January 10, 2014 10:15
Rails model 验证唯一,但不包含相应属性为空的情况
validates :domain, uniqueness: { unless: Proc.new { |shop| shop.domain == '' or shop.domain == nil } }