博客

  • load some plain JavaScript files that do not define modules

    require(["some/script.js"], function() {
        //This function is called after some/script.js has loaded.
    });

    截取自:http://www.requirejs.org/docs/why.html

  • require.js & jQuery & jQueryUI & datepicker &jquery.ui.datepicker-zh-CN

    require.config({
        paths: {
            "jqueryui": '../../../lib/jquery-ui',
            "jquery": "../../../lib/jquery/jquery-1.9.1"
        },
        "shim": {
            "jqueryui/jquery-ui-1.10.3.custom.min": ["jquery"],
            "jqueryui/i18n/jquery.ui.datepicker-zh-CN": ["jqueryui/jquery-ui-1.10.3.custom.min"]
        }
    });
    
    require(['jquery', 'jqueryui/jquery-ui-1.10.3.custom.min', 'jqueryui/i18n/jquery.ui.datepicker-zh-CN'], function ($) {
        $(function () {
            $("#datepicker").datepicker({
                changeMonth: true,
                changeYear: true,
                showOn: "button",
                buttonImage: "/css/jquery-ui-themes/base/images/calendar.gif",
                buttonImageOnly: true
    
            });
        });
       
    })

    代码的关键点:在shim中定义依赖关系,跑起!

  • 比特币:傻瓜式挖矿

    最近各大新闻网站、科技网站都在报道比特币,比特币的价格也是大起大落。肿么傻瓜式挖比特币呢?对于一般网友来说,有个简单的挖矿教程就好了。笔者搜索实验了cgminer,guiminer,Ufasoft Coin,个人觉得guiminer不错。让笔者来亲们进入这个“搞笑的”比特币世界。

    第一步 下载GuiMiner

    image

    下载地址:http://guiminer.org/

    第二步 启动GuiMiner

    image

    第三步 体验挖矿

    server里有一堆矿池,就选默认的slush’s pool吧

    如果仅是体验一下挖矿,可以使用以下体验帐号 lancker.demo 密码:123

    挖还是不挖?

    自用笔记本挖2个小时 挖掘能力1.5Mhash/s 挖到0.00000102 BTC

    算得乐观些 一天挖 0.00001 BTC 即 100000天后可以挖到一个比特币!大概273年!

    采用烤猫(一种专用的挖矿设备),挖掘能力大概300Mhash/s 大概1.3年可以挖到一个币!

    采用矿机,用15Ghash/s的,15000Mhash/s 一天挖1.2个

    以上数据为简单测算,仅供参考。

    小小总结:

    个人电脑用来挖比特币效率太低了。玩比特币还是得使用专业的挖矿工具。

  • 加载非规范的模块

    官方示例:

    http://www.requirejs.org/jqueryui-amd/example/webapp/app.html

    /**
      * Ask for 'require', 'jquery' and 'jqueryui/tabs' as dependencies.
      *
      * 'require' is asked for as best practice, since it used inside the
      * require callback to dynamically load the datepicker. Since 'require'
      * is a module (provided by RequireJS), it is passed as the first argument
      * to the require callback. "req" is used as the function argument name
      * so the RequireJS optimizer will not pick up the dynamic load of
      * the 'jqueryui/datepicker', 'jqueryui/datepicker-fr' modules and
      * include them in the optimized build for main.js (see app.build.js
      * for more information on the optimized main.js build profile.)
      *
      * The require-jquery.js file registers jQuery as a module,
      * so this require callback will receive it as the second function
      * argument, since 'jquery' is the second dependency in the
      * dependency array.
      *
      * 'jquery/ui/tabs' does not export a module
      * value (it just augments jQuery), so it will not have a value for it
      * passed to the require callback. No need to assign a function argument
      * for it.
      */
    require({
        //Set config for finding 'jqueryui'. The path is relative
        //to the location of require-jquery.js.
        paths: {
            jqueryui: 'jqueryui-1.8.13/jqueryui'
        }
    }, ['require', 'jquery', 'jqueryui/tabs'], function (req, $) {
    
        //Wait for dom ready before setting up widgets.
        $(function () {
    
            //Make the tabs.
            $('#tabs')
                .tabs({
                    load: function (event, ui) {
                        //If the second tab is clicked, dynamically load
                        //the datepicker.
                        if (ui.index === 1) {
                            //Load the datepicker in French, on demand.
                            req(['jqueryui/datepicker', 'jqueryui/datepicker-fr'],
                                function () {
                                    $('#datepicker').datepicker();
                                }
                            );
                        }
                    }
                })
                //Make the tabs visible now that the widget has been instantiated.
                .removeClass('invisible');
        });
    });

     

    网上帖子:

    理论上,require.js加载的模块,必须是按照AMD规范、用define()函数定义的模块。但是实际上,虽然已经有一部分流行的函数库(比如jQuery)符合AMD规范,更多的库并不符合。那么,require.js是否能够加载非规范的模块呢?

    回答是可以的。

    这样的模块在用require()加载之前,要先用require.config()方法,定义它们的一些特征。

    举例来说,underscore和backbone这两个库,都没有采用AMD规范编写。如果要加载它们的话,必须先定义它们的特征。

    require.config({     shim: {       ‘underscore’:{         exports: ‘_’       },       ‘backbone’: {         deps: [‘underscore’, ‘jquery’],         exports: ‘Backbone’       }     }   });

     

     

    require.config()接受一个配置对象,这个对象除了有前面说过的paths属性之外,还有一个shim属性,专门用来配置不兼容的模块。具体来说,每个模块要定义(1)exports值(输出的变量名),表明这个模块外部调用时的名称;(2)deps数组,表明该模块的依赖性。

    比如,jQuery的插件可以这样定义:

    shim: {
        'jquery.scroll': {
          deps: ['jquery'],
          exports: 'jQuery.fn.scroll'
        }
      }

    转自:http://www.ruanyifeng.com/blog/2012/11/require_js.html

  • jqueryui datepicker 选择中文年月时错误换行的解决办法

    jQueryUI的datepicker日期选择控件有中文换行问题,看起来很不爽的。网上找到两个修正方案试了试。修正了一下这个bug。

    先睹为快,先看看修正后的效果

    image

     

    解决办法,在jquery-ui-1.8.16.custom.css中找到 .ui-datepicker select.ui-datepicker-year { width: 49%;} 改成 .ui-datepicker select.ui-datepicker-year { width: 45%;}  

    网上写的改成35%,看起来比较别扭的,经测试,45%看起来比较爽~ 

    其他版本的jQueryUI问题也适用!

    参考:http://blog.csdn.net/yzhai/article/details/7013730   +1

    ————————————————————————————————————————–

    台湾的一位亲写到:

    jQuery UI Datepicker繁體中文年月選單換行的小修正

    解決方法很簡單,用編輯器打開 e:\TEMP\jqueryui\development-bundle\themes\[theme name] 底下的 jquery.ui.datepicker.css 或 jquery-ui-1.8.1.custom.css ,找到 .ui-datepicker .ui-datepicker-title 的 class,加上 white-space: nowrap; 存檔修正。

    尝试此方法发现,到是真没有换行了,只是下拉框挤到边上来了,效果不是很好。见下图:

    image

    参考:http://blog.tenyi.com/2010/05/jquery-ui-datepicker.html