Skip to content

Instantly share code, notes, and snippets.

@yushiro
yushiro / replace1.rb
Created March 4, 2014 07:55
Jekyll Bootstrap的页面标题原始代码
<h1>{{ page.title }} <small>{{ page.tagline }}</small></h1>
@yushiro
yushiro / replace2.rb
Created March 4, 2014 07:57
Jekyll Bootstrap的页面标题替换代码
<h1>{{ page.title }} {% if page.tagline %} <small>{{ page.tagline }}</small>{% endif %}</h1>
@yushiro
yushiro / float.html
Created June 14, 2014 13:18
两列左列浮动,右列自适应宽度的四种方法
<!DOCTYPE html>
<html>
<head>
<title>利用haslayout</title>
<style type="text/css">
#left
{float:left;width:100px;height:100px;background-color:#ccc;border:2px solid #333;
}
#right
{overflow:hidden;zoom:1; border:2px solid #333;background:#ccc url(http://www.baidu.com/img/baidu_logo.gif) no-repeat;
@yushiro
yushiro / thumb.cs
Created June 15, 2014 13:59
Generate thumbnail files from uploaded images(ASP.NET中上传图片生成缩略图)
using System.Drawing;
using System.Drawing.Drawing2D;
public void ResizeStream(int imageSize, Stream filePath, string outputPath)
{
var image = Image.FromStream(filePath);
int thumbnailSize = imageSize;
int newWidth, newHeight;
@yushiro
yushiro / gist:0beeed634a720e74e61d
Created October 20, 2014 23:30
非IE浏览器实现removeNode方法
只有 IE 和 Opera 的 HTMLDOMNode 有 removeNode 方法,其他浏览器则不支持。
解决方法:
if(window.Node&&!window.opera){
Node.prototype.removeNode=function(removeChildren){
if(removeChildren||!this.hasChildNodes()){
return this.parentNode.removeChild(this);
}
var $parent=this.parentNode;
@yushiro
yushiro / gist:ad4a832310b11adbf578
Created October 20, 2014 23:31
Ruby中的字符串替换
大部分的字符串替换都是用正则的, 如果需要类似C#的replace那样的功能, 直接用sub().
"foo,bar,baz".sub("foo","boo")
=> "boo,bar,baz"
@yushiro
yushiro / gist:6afc31c8de586a66f963
Created October 20, 2014 23:31
insertAdjacentElement for FireFox
在IE8和Chrome下, 都有insertAdjacentElement这个方法, 但是FF中不支持。
var newElem = document.createElement("span");
newElem.innerHTML = 'this is a new element here';
existingElement.insertAdjacentElement("AfterEnd", newElem);
实现方式有2种:
1. 用其他方法代替(经测试, 下述代码兼容IE7,8/FF/Chrome/Safari)
if(existingElement.nextSibling)
{newElem.parentNode.insertBefore(newElem, existingElement.nextSibling);}
@yushiro
yushiro / gist:fd304bf5c3cde7622a8a
Created October 20, 2014 23:32
56.com视频信息提取
1. 56.com网站
url类型:
http://www.56.com/w54/album-aid-7657069.html
http://www.56.com/w88/album-aid-7609666.html
http://www.56.com/u82/v_NTczMjc3NTk.html
http://www.56.com/w43/play_album-aid-7705385_vid-NDYwNjA4MTg.html
http://player.56.com/v_54644709.swf
对应的json请求:
@yushiro
yushiro / gist:88c8f54267697e42105e
Created October 20, 2014 23:32
AutoHotKey针对窗体发送按键消息
#Persistent #NoEnv
v_Enable=0 $F12:: { Winget, wowid, list, 魔兽世界 WinSetTitle, ahk_id%wowid1%, , 魔兽世界1# WinSetTitle, ahk_id%wowid2%, , 魔兽世界2# v_Enable:=!v_Enable If (v_Enable=0) SetTimer, Label0, Off Else SetTimer, Label0, 1 } Return
Label0: {
ControlSend,, {F11}, ahk_id %wowid1% sleep, 200 ControlSend,, {F11}, ahk_id %wowid2% sleep, 200 } Return
@yushiro
yushiro / gist:9c81b123138ce396f834
Created October 20, 2014 23:34
Android界面控件遍历代码
用instanceof来判断是否是指定的控件类型
TableLayout myLayOut = (TableLayout)findViewById(R.id.tableLayout1);
for (int i = 0; i < myLayOut.getChildCount(); i++) {
View v = myLayOut.getChildAt(i);
if ( v instanceof ImageView){
ImageView myImageView = (ImageView)myLayOut.getChildAt(i);
myImageView.setOnClickListener(new myOnclickListener());
}
}