Skip to content

Instantly share code, notes, and snippets.

@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: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:ad4a832310b11adbf578
Created October 20, 2014 23:31
Ruby中的字符串替换
大部分的字符串替换都是用正则的, 如果需要类似C#的replace那样的功能, 直接用sub().
"foo,bar,baz".sub("foo","boo")
=> "boo,bar,baz"
@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 / 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 / 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 / replace2.rb
Created March 4, 2014 07:57
Jekyll Bootstrap的页面标题替换代码
<h1>{{ page.title }} {% if page.tagline %} <small>{{ page.tagline }}</small>{% endif %}</h1>
@yushiro
yushiro / replace1.rb
Created March 4, 2014 07:55
Jekyll Bootstrap的页面标题原始代码
<h1>{{ page.title }} <small>{{ page.tagline }}</small></h1>
@yushiro
yushiro / javascript.md
Last active January 3, 2016 07:48
javascript常用代码

###取当前URL中的页面名称

 window.location.href.split('/').pop().split('#')[0];
@yushiro
yushiro / chrome.md
Last active January 3, 2016 02:39
不用chrome插件, 在chrome下调试json格式的数据

在查看源码的页面, 执行

JSON.parse($('.webkit-line-content').innerHTML);

或者在普通tab页面, 执行

var result = JSON.parse($('body>pre').innerHTML);