Skip to content

Instantly share code, notes, and snippets.

View mxgrn's full-sized avatar

Max Gorin mxgrn

View GitHub Profile
/*
CheckColumn plugin from the "Editable Grid" example on http://extjs.com/deploy/dev/examples/
The problem with it is that when a new record is added to the store, the corresponding field value
is set to an empty string, instead of being set to false. Here's the fix for it.
*/
Ext.grid.CheckColumn = function(config){
Ext.apply(this, config);
if(!this.id){
this.id = Ext.id();
}
module Netzke
class TreeNavigator < BorderLayoutPanel
# BorderLayoutPanel's regions
def initial_aggregatees
{
:west => {
:widget_class_name => "TreePanel",
:data_class_name => config[:tree_data_class_name],
:region_config => {
class Netzke::TreePanel < Netzke::Base
api :get_children
def self.js_base_class
"Ext.tree.TreePanel"
end
def self.js_extend_properties
{
:root => {:text => '/', :id => 'source'}
# Example of Netzke Helper
module Netzke::Helpers::GridPanelClerk
# which model's methods should be used as virtual column, along with configuration
def self.virtual_attributes
[:name]
end
# preconfigure some columns
def self.attributes_config
{

= General suggestions:

  • In the beginning, keep the current method naming to avoid confusion (and to be able to search on method names), but mark in the comments what's probably to be renamed.
  • In most cases it would be hard to simplify things without a deep refactor. I may forget why I did something one way or another, but each time I decide "this should not be needed", sooner or later it proves needed in a specific scenario... Tests would be of great help here.

= Core

  • Class-level configuration:
    • Netzke::Base.config and Netzke::GridPanel.config are decoupled.
  • Example of usage:
module Netzke
class FileUploader < FormPanel
INITIAL_UPLOAD_FIELDS_NUMBER = 5
# Extra javascripts
def self.include_js
[
"#{File.dirname(__FILE__)}/file_uploader_extras/file_uploader.js"
]
end
// in grid_panel_pre.js:
// React on before edit event to set the recordId property in the editor
this.on('beforeedit', function(e){
e.grid.getColumnModel().getCellEditor(e.column, e.record).field.recordId = e.record.id;
});
@mxgrn
mxgrn / gist:638919
Created October 21, 2010 17:30
Wrong scope of yield?
# (Ruby version: 1.9.2)
#
##### A million-dollar question: why the following isn't working?
#
#
class A
def self.metamethod(name)
define_method(name) do
yield
@mxgrn
mxgrn / gist:663933
Created November 5, 2010 10:24
Git's pre-commit hook to remove trailing whitespaces/tabs
#!/bin/sh
#
# This will abort "git commit" and remove the trailing whitespaces from the files to be committed.
# Simply repeating the last "git commit" command will do the commit then.
#
# Put this into .git/hooks/pre-commit, and chmod +x it.
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
@mxgrn
mxgrn / gist:5402155
Last active October 19, 2018 02:19 — forked from billygoat/gist:5320505
Adds a new entry in nvALT, with title set to page title, tags set to "bookmarks", and body containing page title, link, and text selected on page (if present).
/* Source code */
javascript:(function(){
var w=window,d=document,pageSelectedTxt=w.getSelection?w.getSelection():(d.getSelection)?d.getSelection():(d.selection?d.selection.createRange().text:0),pageTitle=d.title,pageUri=w.location.href,tmplt="";
tmplt="Title: "+pageTitle+"\nLink: "+pageUri+"\n";
if (pageSelectedTxt != "") {
pageSelectedTxt="\n---\n"+pageSelectedTxt;
}
w.location.href="nvalt://make/?txt="+encodeURIComponent(tmplt+pageSelectedTxt)+"&title="+encodeURIComponent(pageTitle)+"&tags=bookmarks";
})();