- 浏览: 248041 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
aqyzcs:
你好,我想问一下,这个羽毛(Feather)图片编辑器里面自带 ...
给自己的Web站点嵌入一个免费的图片编辑器 -
wwx840723:
$db = ADONewConnection("ms ...
为PHP微软SQL Server驱动加入更好的ADODB支持 -
qxinfo:
还不如看看这个简单版的crmhttp://crm.fzerp. ...
用PHP开发CRM一年多小记 -
星光1224:
谢谢分享~~有一个问题:http://renzhen.itey ...
客户端JavaScript实战撤销恢复功能总结 -
hanbiaoo:
安装node.js, uglifyjs都不是必须的。文件目录调 ...
放弃繁琐的配置!直接使用UglifyJS批量压缩目录下所有JS文件
收藏列表
标题 | 标签 | 来源 | |
小说分割 | jruby | ||
file='E:\book\tmpnovel\ebook\jinhun\a.txt' start="黄鹰《" txtend="》" regxp=/^#{start}(.+?)#{txtend}/u titlenum=Hash.new do |h,k| h[k]=0 end title='' content='' File.open(file,'r') do |f| f.each_line do |l| if l=~regxp if content !='' && title !='' puts "add txt #{title}" titlenum[title]+=1 File.open('E:\book\tmpnovel\ebook\jinhun\\'+title+titlenum[title].to_s+'.txt','a') do |f2| f2.write(content) end end title=$1 content='' else content+=l content+="\n" end end end if content !='' && title !='' titlenum[title]+=1 File.open('E:\book\tmpnovel\ebook\jinhun\\'+title+titlenum[title].to_s+'.txt','a') do |f2| f2.write(content) end end |
|||
PHPExcel生成xlsx文件并下载 | php | ||
require_once P_LIB."/Excel/PHPExcel.php"; $objPHPExcel = new PHPExcel(); $objPHPExcel->setActiveSheetIndex(0)->setTitle('Products'); $sheet=$objPHPExcel->getActiveSheet(); $exceli=0; $excelj=1; foreach($rows as $columns){ $exceli=0; foreach($columns as $cell){ $sheet->getCellByColumnAndRow($exceli, $excelj)->setValueExplicit($cell, PHPExcel_Cell_DataType::TYPE_STRING); $exceli++; } $excelj++; } header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="products.xlsx"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); exit; |
|||
jquery.ui.resizable的innerIframeFix插件(参考draggable) | jquery ui, javascript, 客户端js | ||
$.ui.plugin.add("resizable", "innerIframeFix", { start: function(event, ui) { var o = $(this).data('resizable').options; $(o.innerIframeFix === true ? "iframe" : o.iframeFix,this).each(function() { $('<div class="ui-resizable-innerIframeFix" style="background: #fff;"></div>') .css({ width: this.offsetWidth+"px", height: this.offsetHeight+"px", position: "absolute", opacity: "0.001", zIndex: 1000 }) .css($(this).offset()) .appendTo("body"); }); }, stop: function(event, ui) { $("div.ui-resizable-innerIframeFix").each(function() { this.parentNode.removeChild(this); }); //Remove frame helpers }, resize: function(event, ui) { $("div.ui-resizable-innerIframeFix").width(ui.size.width).height(ui.size.height).css($(this).offset()); } }); |
|||
jquery.ui.modselectable,基于ui.mouse的模块选中操作js代码 | javascript, jquery ui | ||
(function( $, undefined ) { $.widget("ui.modselectable", $.ui.mouse, { options: { appendTo: 'body', distance: 0, filter: '*' }, _create: function() { var self = this; this.element.addClass("ui-modselectable"); this.dragged = false; // cache selectee children based on filter var selectees=$(this.options.filter, this.element[0]); this.selectees = selectees; this.leftmargin=($('#scroll_container').width()-$('#canvas').width())/2; this._mouseInit(); this.helper = $("<div class='ui-modselectable-helper'></div>"); }, refresh:function(){ var self=this; this.selectees.each(function() { var $this = $(this); $.data(this, "selectable-item", { element: this, $element: $this, left: parseInt($this.css('left'))+self.leftmargin, top: parseInt($this.css('top')), right: parseInt($this.css('left'))+self.leftmargin + $this.outerWidth(), bottom: parseInt($this.css('top')) + $this.outerHeight(), startselected: false }); }); }, destroy: function() { this.selectees .removeData("modselectable-item"); this.element .removeClass("ui-modselectable ui-modselectable-disabled") .removeData("modselectable") .unbind(".modselectable"); this._mouseDestroy(); return this; }, _mouseDown: function(event) { // don't let more than one widget handle mouseStart // TODO: figure out why we have to use originalEvent event.originalEvent = event.originalEvent || {}; if (event.originalEvent.mouseHandled) { return; } // we may have missed mouseup (out of window) (this._mouseStarted && this._mouseUp(event)); this._mouseDownEvent = event; var self = this, btnIsLeft = (event.which == 1), elIsCancel = (typeof this.options.cancel == "string" ? $(event.target).parents().add(event.target).filter(this.options.cancel).length : false); if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) { return true; } this.mouseDelayMet = !this.options.delay; if (!this.mouseDelayMet) { this._mouseDelayTimer = setTimeout(function() { self.mouseDelayMet = true; }, this.options.delay); } if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) { this._mouseStarted = (this._mouseStart(event) !== false); if (!this._mouseStarted) { if(!$(event.target).is(this.options.notpreventclick)){ event.preventDefault(); } return true; } } // Click event may never have fired (Gecko & Opera) if (true === $.data(event.target, this.widgetName + '.preventClickEvent')) { $.removeData(event.target, this.widgetName + '.preventClickEvent'); } // these delegates are required to keep context this._mouseMoveDelegate = function(event) { return self._mouseMove(event); }; this._mouseUpDelegate = function(event) { return self._mouseUp(event); }; $(document) .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate) .bind('mouseup.'+this.widgetName, this._mouseUpDelegate); event.preventDefault(); event.originalEvent.mouseHandled = true; return true; }, selectedModsContainer:function(){ var comp_domid=$(document).data('selected_component'); if(comp_domid){ var ctr=$('.ui-modselected').not('#'+comp_domid).first().closest('.combination_container'); if($('#'+comp_domid).find(ctr).length>0) return ctr; } }, _mouseStart: function(event) { var self = this; var doSelect = false ; var doInComponent=false; var doSameContainer=true; this.opos = [event.pageX, event.pageY+this.element.scrollTop()]; if (this.options.notselectable) return; if (this.options.disabled) return; var options = this.options; var comp_domid=$(document).data('selected_component'); var selectedmodslen=$('.ui-modselected').length; this.selectees = $(options.filter, this.element[0]); if(comp_domid){ selectedmodslen=$('.ui-modselected').not('#'+comp_domid).length; var sub_mods=$('#'+comp_domid).find(options.sub_filter); this.selectees =this.selectees.add(sub_mods); var startcontainer=$(event.target).closest('.combination_container'); var selectedmodsctr=this.selectedModsContainer() if($('#'+comp_domid).find(startcontainer).length>0){ this.mouseStartContainer=startcontainer; if(selectedmodslen>0&&(!selectedmodsctr||!startcontainer.is(selectedmodsctr))){ doSameContainer=false; } }else{ if(selectedmodslen>0&&selectedmodsctr){ doSameContainer=false; } } } this.refresh(); $(options.appendTo).append(this.helper); // position helper (lasso) this.helper.css({ "left": event.clientX, "top": event.clientY, "width": 0, "height": 0 }); $.unselectbgdiv(); $(event.target).parents().andSelf().each(function() { var selectee = $(this); if(selectee.is('.custom_bg')){ $.selectbgdiv(selectee); } if (selectee.is(self.options.filter)||selectee.is(self.options.sub_filter)) { if(comp_domid&&comp_domid==selectee.prop('id')){ doInComponent=true; return; }else{ doSelect =true; } if(selectee.hasClass('ui-modselected')){ if(event.metaKey){ $.hidWidgetBorder(selectee); }else{ // 图文模块相关 2012/2/14 if($(this).hasClass('graphic_edited')) actived_graphic(); $.showWidgetBorder(selectee); } }else{ if(!event.metaKey){ self.selectees.each(function(){ // 图文模块相关 2012/2/21 if($(this).hasClass('graphic_edited')) actived_graphic(); $.hidWidgetBorder($(this)); }); $.showWidgetBorder(selectee); }else{ if(doSameContainer) $.showWidgetBorder(selectee); } } return false; } }); if(selectedmodslen==0&&!doInComponent){ $.deActivateComponent(); } if(event.metaKey&&!doSameContainer){ this.helper.remove(); this.mouseStartContainer=null; return false; }else{ if(!doInComponent){ $.deActivateComponent(); } } if(!doSelect){ if(!event.metaKey){ $('.ui-modselected').each(function(){ $.hidWidgetBorder($(this)); // 图文模块相关 2012/2/14 if($(this).hasClass('graphic_edited')) actived_graphic(); }); } }else{ this.helper.remove(); this.mouseStartContainer=null; return false; } }, _mouseDrag: function(event) { var self = this; this.dragged = true; if (this.options.notselectable) return; if (this.options.disabled) return; var options = this.options; var x1 = this.opos[0], y1 = this.opos[1], x2 = event.pageX, y2 = event.pageY+this.element.scrollTop(); if (x1 > x2) { var tmp = x2; x2 = x1; x1 = tmp; } if (y1 > y2) { var tmp = y2; y2 = y1; y1 = tmp; } this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1}); var additionparam={left:0,top:0}; var startContainer=this.mouseStartContainer; if(startContainer){ additionparam={ left:startContainer.offset().left-this.leftmargin, top:startContainer.offset().top+this.element.scrollTop() } } this.selectees.each(function() { var selectee = $.data(this, "selectable-item"); //prevent helper from being selected if appendTo: selectable if (!selectee || selectee.element == self.element[0]) return; if(startContainer&&startContainer.find(selectee.element).length==0) return; var hit = false; hit = (selectee.left+additionparam.left > x1 && selectee.right+additionparam.left < x2 && selectee.top+additionparam.top > y1 && selectee.bottom+additionparam.top < y2); selectee =$(selectee.element); if (hit) { // SELECT if(event.metaKey){ if(selectee.is('.ui-modselected')){ $.hidWidgetBorder(selectee); }else{ $.showWidgetBorder(selectee); } }else{ $.showWidgetBorder(selectee); } } else { // UNSELECT if(!event.metaKey){ if(selectee.is('.ui-modselected')){ $.hidWidgetBorder(selectee); } } } }); return false; }, _mouseStop: function(event) { var self = this; this.dragged = false; var options = this.options; this._trigger("stop", event); this.helper.remove(); this.mouseStartContainer=null; return false; } }); $.extend($.ui.modselectable, { version: "1.8.16" }); })(jQuery); |
|||
改良的undo.js | javascript, 客户端js | ||
/* * Undo.js - A undo/redo framework for JavaScript * * http://jzaefferer.github.com/undo * * Copyright (c) 2011 Jörn Zaefferer * MIT licensed. */ (function() { // based on Backbone.js' inherits var ctor = function(){}; var inherits = function(parent, protoProps) { var child; if (protoProps && protoProps.hasOwnProperty('constructor')) { child = protoProps.constructor; } else { child = function(){ return parent.apply(this, arguments); }; } ctor.prototype = parent.prototype; child.prototype = new ctor(); if (protoProps) extend(child.prototype, protoProps); child.prototype.constructor = child; child.__super__ = parent.prototype; return child; }; function extend(target, ref) { for ( name in ref ) { var value = ref[name]; if (value !== undefined) { target[ name ] = value; } } return target; }; var Undo; if (typeof exports !== 'undefined') { Undo = exports; } else { Undo = this.Undo = {}; } Undo.Stack = function() { this.commands = []; this.stackPosition = -1; this.savePosition = -1; }; extend(Undo.Stack.prototype, { execute: function(command) { this._clearRedo(); command.execute(); this.commands.push(command); this.stackPosition++; this.changed(); }, undo: function() { if(!this.canUndo()) return; this.commands[this.stackPosition].undo(); this.stackPosition--; this.changed(); }, canUndo: function() { return this.stackPosition >= 0; }, redo: function() { if(!this.canRedo()) return; this.stackPosition++; this.commands[this.stackPosition].redo(); this.changed(); }, canRedo: function() { return this.stackPosition < this.commands.length - 1; }, save: function() { this.savePosition = this.stackPosition; this.changed(); }, dirty: function() { return this.stackPosition != this.savePosition; }, clearStack:function(){ this.commands = []; this.stackPosition = -1; this.savePosition = -1; this.changed(); }, _clearRedo: function() { // TODO there's probably a more efficient way for this this.commands = this.commands.slice(0, this.stackPosition + 1); }, changed: function() { // do nothing, override } }); Undo.Command = function(name) { this.name = name; } var up = new Error("override me!"); extend(Undo.Command.prototype, { execute: function() { throw up; }, undo: function() { throw up; }, redo: function() { this.execute(); } }); Undo.Command.extend = function(protoProps) { var child = inherits(this, protoProps); child.extend = Undo.Command.extend; return child; }; //扩展wopop 2.0撤销框架 by renzhen var undo_stack = new Undo.Stack(); var Undo_Container= Undo.Command.extend({ constructor:function(){ this.undoarr=[]; }, execute: function() {}, undo: function() { var undoarr=this.undoarr; for(var i=0;i<undoarr.length;i++){ var undoobj=undoarr[i]; undoobj.undo(); } }, redo: function() { var undoarr=this.undoarr; for(var i=0;i<undoarr.length;i++){ var undoobj=undoarr[i]; undoobj.redo(); } }, add:function(undoobj){ this.undoarr.push(undoobj); }, insert:function(){ if(this.undoarr.length==0) return; if(this.undoarr.length==1){ undo_stack.execute(this.undoarr[0]); }else{ undo_stack.execute(this); } } }); window.undo_stack=undo_stack; var stack_is_open=true; var undo__multi_container=null; var defaultcommandobj={ execute:$.noop, setOldVal:function(val){ this.oldValue =val; }, setNewVal:function(val){ this.newValue =val; }, insert:function(){ if(stack_is_open && !this.equals()){ if(undo__multi_container != null){ undo__multi_container.add(this); }else{ undo_stack.execute(this); } } }, insertWithNewVal:function(newval){ this.setNewVal(newval); this.insert(); }, insertWithVals:function(oldval,newval){ this.setOldVal(oldval); this.setNewVal(newval); this.insert(); } }; Undo.Transaction={ start: function(is_open){ if(undo__multi_container != null){ Undo.Transaction.end(); } if(typeof(is_open) =='undefined'){ is_open=true; } stack_is_open=is_open?true:false; undo__multi_container=new Undo_Container(); }, end:function(){ stack_is_open=true; if(undo__multi_container != null){ undo__multi_container.insert(); undo__multi_container=null; } } }; Undo.Command.DefaultEqAct=function(oldval,newval){ if( $.isPlainObject(oldval) && $.isPlainObject(newval)){ var mergedobj=$.extend({},oldval,newval); for(var k in mergedobj){ if(!Undo.Command.DefaultEqAct(oldval[k],newval[k])) return false; } return true; }else if($.isArray(oldval) && $.isArray(newval)){ if(oldval.length != newval.length ) return false; for(var i=0;i<oldval.length;i++){ if(!Undo.Command.DefaultEqAct(oldval[i],newval[i])) return false; } return true; }else{ return oldval==newval; } } Undo.Command.createGlobalCommand=function(undoobj,options){ var undofunc; var redofunc; if($.isFunction(undoobj)){ undofunc=redofunc=undoobj; }else{ var obj=$.extend({undo:$.noop,redo:$.noop},undoobj); undofunc=obj.undo; redofunc=obj.redo; } var opts=$.extend({returntype:'obj',equalact:'default'},options); var eqact=opts.equalact; if(eqact=='default') eqact=Undo.Command.DefaultEqAct; else if(!$.isFunction(eqact)){ eqact=function(){return false;} } var cmdclass = Undo.Command.extend($.extend({constructor: function(){}},defaultcommandobj,{ undo: function() { undofunc(this.oldValue); }, equals:function(){ return eqact(this.oldValue,this.newValue); }, redo: function() { redofunc(this.newValue); } })); if(opts.returntype=='class') return cmdclass; else return new cmdclass(); } Undo.Command.createModuleCommand=function(undoobj,blockid,options){ var undofunc; var redofunc; if($.isFunction(undoobj)){ undofunc=redofunc=undoobj; }else{ var obj=$.extend({undo:$.noop,redo:$.noop},undoobj); undofunc=obj.undo; redofunc=obj.redo; } var opts=$.extend({returntype:'obj',equalact:'default'},options); var eqact=opts.equalact; if(eqact=='default') eqact=Undo.Command.DefaultEqAct; else if(!$.isFunction(eqact)){ eqact=function(){return false;} } var cmdclass = Undo.Command.extend($.extend({ constructor: function(modid){ this.blockid=modid; } },defaultcommandobj,{ undo: function() { undofunc(this.blockid,this.oldValue); }, equals:function(){ return eqact(this.oldValue,this.newValue); }, redo: function() { redofunc(this.blockid,this.newValue); } })); if(opts.returntype=='class') return cmdclass; else return new cmdclass(blockid); } }).call(this); |
|||
JRuby使用原生swing复制字符串到剪贴板 | jruby, swing, 剪贴板 | ||
require 'java' module JRubyClipboard import java.awt.Toolkit import java.awt.datatransfer.StringSelection import java.awt.datatransfer.DataFlavor def copy_str_to_clip(str) @@clipboard||=Toolkit.getDefaultToolkit.getSystemClipboard() selection=StringSelection.new(str) @@clipboard.setContents(selection,nil) end def paste_str_from_clip() str=nil @@clipboard||=Toolkit.getDefaultToolkit.getSystemClipboard() str=@@clipboard.getData(DataFlavor.stringFlavor) if @@clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor) str end module_function :copy_str_to_clip ,:paste_str_from_clip end |
|||
我做的jruby对schedule操作的封装 | jruby | ||
require "java" import java.util.concurrent.TimeUnit class BlockRunnable include java.lang.Runnable def initialize(params=nil,&block) @params=params @block=block end def run if @block if @params.nil? @block.call else @block.call(*@params) end end end end class ScheduleTimer @@service=java.util.concurrent.Executors.newScheduledThreadPool(1) def self.set_time_out(delay,&block) @@service.schedule(BlockRunnable.new(nil,&block),delay,TimeUnit::SECONDS) end def self.set_interval(initdelay,delay,&block) @@service.scheduleAtFixedRate(BlockRunnable.new(nil,&block),initdelay,delay,TimeUnit::SECONDS) end def self.shutdown @@service.shutdown end end puts Time.now # ScheduleTimer.set_time_out(10) do # puts Time.now # end i=0 ScheduleTimer.set_interval(10,5) do puts Time.now i+=1 if i>2 ScheduleTimer.shutdown `cmdmp3win music.mp3` end end |
|||
我写的小说分割脚本 | |||
require "commonlib" nousestrings=['</DIV>',/<\/?style>/,'.pp a{color:#f00;text-decoration:underline;}','【求鲜花和贵宾票,谢谢支持。】<!---文章内容结束--->','<script type="text/javascript" src="http://js.txt6.net/new/soso999.js"></script>',/^\s*\r\n/] titleregx=/^正文\s+/ content="" index=0 File.open("ori.txt",'r') do |rf| rf.each do |line| if line=~titleregx outputfilename=sprintf("tmpnovel/%02d.txt",index) nousestrings.each do |nouse| content.gsub!(nouse,'') end file_puts_content(outputfilename,content) content=line content << "\r\n" index+=1 # break if index==5 else content << line content << "\r\n" end end end |
|||
根据电视剧名字获取第几集 | |||
def getTVJishu(fromname,replacestrs) topathname=fromname.dup fileext=File.extname(fromname) topathname.gsub!("#{fileext}",'') replacestrs.each do |str| topathname.gsub!(str,'') end numarr=topathname.scan(/\d+/) numarr[0]+"#{fileext}" end fromname="古灵精探国02.rmvb" replacestrs=[] toname=getTVJishu(fromname,replacestrs) puts toname |
|||
CSVIterator.php | php | http://www.phpclasses.org/browse/file/27541.html | |
<?php class CSVIterator implements Iterator { const ROW_SIZE = 4096; private $filePointer; private $currentElement; private $rowCounter; private $delimiter; private $headrow; public function __construct( $file, $hasheader=false,$delimiter = ',' ) { $this->filePointer = fopen( $file, 'r' ); $this->delimiter = $delimiter; if($hasheader) $this->headrow=fgetcsv( $this->filePointer, self::ROW_SIZE, $this->delimiter ); } public function rewind() { $this->rowCounter = 0; rewind( $this->filePointer ); } public function current() { $this->currentElement = fgetcsv( $this->filePointer, self::ROW_SIZE, $this->delimiter ); if(!empty($this->headrow)){ $this->currentElement =array_combine($this->headrow,$this->currentElement); } $this->rowCounter++; return $this->currentElement; } public function key() { return $this->rowCounter; } public function next() { return !feof( $this->filePointer ); } public function valid() { if( !$this->next() ) { fclose( $this->filePointer ); return FALSE; } return TRUE; } } // end class ?> |