Skip to content

Instantly share code, notes, and snippets.

View giiska's full-sized avatar
🌴
On vacation

Null giiska

🌴
On vacation
  • Godada
View GitHub Profile
@giiska
giiska / 0readme.md
Last active August 29, 2015 14:02
fixed width column with fluid row container by bootstrap grid system
@giiska
giiska / 0readme.md
Last active August 29, 2015 14:03
set Django debug mode for site running inside virtualbox/vagrant

When visit Virtual Box site, the client ip is gateway of virtual machine, not your dev machine ip.

Check the true client ip

  • Add import pdb;pdb.set_trace() to any Django view, and open the view in chrome
  • Switch to termianl, request.META.get('REMOTE_ADDR', None) at the break point
  • The result is the true client ip address
@giiska
giiska / a.js
Created July 7, 2014 06:19
Using custom headers with Backbone.sync backbone restful token
/*
* Using AMD/RequireJS
*
* The `auth` module handles OAuth and stores the
* access token that needs to be sent in a header
*/
define(['api/auth'], function (auth) {
'use strict';
/*
// ==UserScript==
// @name socialbase content list replace url
// @namespace http://use.i.E.your.homepage/
// @version 0.1.1
// @description enter something useful
// @match http://socialbase.hk/socialbase/content/*
// @copyright 2014+, bammoo
// ==/UserScript==
require(['jquery'], function($) {
@giiska
giiska / several ways to add,get,filter-when-save derived attributes for backbone model.md
Last active August 29, 2015 14:03
several ways to add/get/filter-when-save derived attributes for backbone model

set attributes mannuly

// Cons: make code too redundant
var MyModel = Backbone.Model.extend({
    initialize: function() {
        this.updateDerivedAttributes();
        this.on('change:start_at', this.updateDerivedAttributes, this);
    },
 updateDerivedAttributes: function() {
@giiska
giiska / customise-backbone-save-api-param.js
Last active August 29, 2015 14:03
Set `options.attrs` will allow you customise api param
// when model.attributes is different from the params to save
// e.g. when save to restful api, one attr should be `resource_uri`
// formated as string type, but the returned attr value in json is object formated
var model = new Backbone.Model();
model.save(null, {
wait: true,
success: function() {
},
attrs: _.omit(model.attributes, 'selected')
});
@giiska
giiska / a.js
Created July 11, 2014 10:54
require config path before load require.js
var require = {
paths: {
'jquery': '../../bower_components/zepto/zepto.min'
}
}
@giiska
giiska / zepto.js
Created July 12, 2014 06:06
set require.config path of `jquery` to `zepto` when use backbone-amd
/**
* extend/zepto.js
*/
define([
'zepto'
], function() {
"use strict";
@giiska
giiska / .gemrc
Last active August 29, 2015 14:04 — forked from jch/.gemrc
中国用户的 gemrc, gemrc for coder in China
# http://guides.rubygems.org/command-reference/#gem-environment
---
:backtrace: true
:bulk_threshold: 1000
:benchmark: false
:sources:
- http://ruby.taobao.org/
:update_sources: true
:verbose: true
gem: --no-document
@giiska
giiska / a.js
Created July 24, 2014 08:42
jquery.validate: accordion show when form in it is invalid by config `invalidHandler`
$form.validate({
ignore: '.ignore',
rules: rules,
messages: messages,
invalidHandler: function(event, validator) {
// console.log(event, validator);
var errorEl = validator.findLastActive() || validator.errorList.length && validator.errorList[0].element;
if(errorEl)
$(errorEl).closest('.accordion-body').collapse('show');
},