Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hzmangel
hzmangel / gist:6737739
Created September 28, 2013 02:21
Load another multi-page page in jQuery

The default loading only loads first page from the second multi-page page, so make sure to add :rel => :external to the link/button, or add ajaxFormsEnabled : false like this:

$(document).bind("mobileinit", function(){
  $.extend($.mobile , {
  ajaxFormsEnabled : false
  });
});

For the form with submit button, uses data-ajax=false.

@hzmangel
hzmangel / gist:6737026
Last active December 24, 2015 03:19
Flexslider and jQuery mobile

jQuery mobile is using ajax loading of pages, which may not show flexslider correctly, especially for page with more than one image. Here are two solutions:

  1. Disable the ajax loading for special pages:

    $(document).bind("mobileinit", function(){ $.mobile.ajaxEnabled = false; });

@hzmangel
hzmangel / gist:6465692
Last active December 22, 2015 11:28
Using another layout for devise view
class ApplicationController < ActionController::Base
layout :layout
private
def layout
if devise_controller?
# NOTICE: symbol is *NOT* allowed here, use string instead.
"devise"
@hzmangel
hzmangel / gist:5999154
Created July 15, 2013 10:59
form upload file
如果是用form上传文件的话,一定要加上multipart/form-data啊,要不然传不上去啊啊啊。一个下午的教训,嗯。
@hzmangel
hzmangel / gist:5980431
Created July 12, 2013 00:22
Enable javascript on remote selenium browser
require 'watir-webdriver'
require 'selenium/server'
include Selenium
caps = WebDriver::Remote::Capabilities.htmlunit(:javascript_enabled => true)
@browser = Watir::Browser.new(:remote, :url => 'http://127.0.0.1:4444/wd/hub', :desired_capabilities => caps)
@hzmangel
hzmangel / gist:5421035
Created April 19, 2013 15:17
Select tag used in rails
# Rails code
# @foo = [1,2,3,4]
= select_tag "foo", options_for_select(@foo), :prompt => "Please select a foo"
# @bar is an collection of objects, each of which has key_method key and value_method val
= select_tag "bar", options_from_collection_for_select(@bar), :prompt => "Please select a bar"
@hzmangel
hzmangel / gist:5420793
Last active December 16, 2015 10:29
Generate 7 days date list from now on in Ruby
# Rails code
(Date.today..1.week.from_now.to_date).map { |d| d.strftime("%m/%d")}
@hzmangel
hzmangel / x
Created July 15, 2009 07:53 — forked from holin/x
CmdUtils.CreateCommand({
names: ["dictcn", "dcn"],
author: {
name: "Hu Ziming",
email: "hzmangel@gmail.com"
},
contributors: ["Hu Ziming", "azuwis"],
icon : "http://dict.cn/favicon.ico",
description: "Consulting the word from <a>http://dict.cn</a>.",
help: "Consulting the word from <a>http://dict.cn</a>.",
#!/usr/bin/python
# -*- coding: utf8 -*-
# Author: Hu Ziming <hzmangel@gmail.com>
#
# License:
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@hzmangel
hzmangel / x
Created November 17, 2008 09:16 — forked from azuwis/x
CmdUtils.CreateCommand({
name: ["dictcn", "dcn"],
author: {
name: "Hu Ziming",
email: "hzmangel@gmail.com"
},
contributors: ["Hu Ziming", "azuwis"],
icon : "http://dict.cn/favicon.ico",
description: "Consulting the word from <a href=\"http://dict.cn\">http://dict.cn</a>.",
help: "Consulting the word from <a href=\"http://dict.cn\">http://dict.cn</a>.",