Skip to content

Instantly share code, notes, and snippets.

View CarlLee's full-sized avatar

Carl Lee CarlLee

  • Chongqing China
View GitHub Profile
function embed_images($content){
$embed_images = preg_replace_callback('/https?:\/\/([A-z0-9]+[_\-]?[A-z0-9]+\.)*[A-z0-9]+\-?[A-z0-9]+\.[A-z]{2,}(\/.*)*\/?/i', "addimg",$content);
return $embed_images;
}
function addimg($url){
global $post;
$title = $post ->post_title;
$imgurl = preg_replace('/((^http[s]{0,1}:)\/\/(.+).(gif|jpg|bmp|png))/i', '<img src="$1" alt="'.$title.'" /><pre>$1</pre>',$url[0]);
if($imgurl !== $url[0]){
@CarlLee
CarlLee / gist:5418071
Created April 19, 2013 04:04
a function to replace image URLs into <img>
function embed_images($content){
return preg_replace('/(https?\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(?:\/\S*?)?(?:[a-zA-Z0-9_])+\.(?:jpg|jpeg|gif|png))/i', '<img src="$1"/>', $content);
}
add_filter(the_content', 'embed_images');
@CarlLee
CarlLee / v2ex-customize.css
Last active December 16, 2015 10:09
v2ex gist enhancement
#Main>.box>.inner>table>tbody>tr, #Main>.box>.cell>table>tbody>tr{
position:relative;
}
#Main>.box>.inner>table>tbody>tr>td:nth-child(3), #Main>.box>.cell>table>tbody>tr>td:nth-child(3){
padding-right: 4em;
}
#Main>.box>.inner>table>tbody>tr>td:nth-child(4), #Main>.box>.cell>table>tbody>tr>td:nth-child(4){
position:absolute;
top:0px;
right:8px;
@CarlLee
CarlLee / scroll.js
Last active December 16, 2015 13:29
scroll to mid of page when load
window.addEventListener('load', function(){
var body = document.body,
html = document.documentElement;
var height = Math.max( body.scrollHeight, body.offsetHeight,
html.clientHeight, html.scrollHeight, html.offsetHeight );
console.log(height/2 - window.innerHeight/2);
window.scrollTo(0, height/2 - window.innerHeight/2);
});
@CarlLee
CarlLee / problem1.js
Last active December 16, 2015 13:38
nimbusbase interview problems
//output:
//906609
//993*913
//cost: 0.122 secs
var start = new Date()
var last = 0;
var lastTxt = '';
for (var i = 999; i > 99; i--){
for(var j = 999; j > 99; j--){
var val = i*j;
@CarlLee
CarlLee / simple-string-matching.html
Created April 23, 2013 14:11
Simple string matching algorithm: * for matching any number(>= 0) of characters; ? for matching one random character;
<script>
function match(input, rule, matched){
if(input.length == 0 && rule.length != 0){
return '';
}
if(rule.length == 0){
return matched;
}
var c1 = rule[0];
var c2 = input[0];
@CarlLee
CarlLee / punctuation.js
Last active May 30, 2019 12:14
Match punctuation in English/Chinese sentenses
var re = /([\[\]\,.?"\(\)+_*\/\\&\$#^@!%~`<>:;\{\}?,。·!¥……()+{}【】、|《》]|(?!\s)'\s+|\s+'(?!\s))/ig;
content.replace(re, '');
@CarlLee
CarlLee / nimbusStorage.coffee
Last active December 16, 2015 19:39
NimbusBase angularjs integration.
Nimbus.angularService = ()->
(name, attrs, sync_callback)->
store = Nimbus.Model.setup(name, attrs)
store.sync_all(sync_callback)
store
@CarlLee
CarlLee / ceaser.js
Last active December 17, 2015 01:39
Ceaser code travese
ceaser_code = function(comb){
for(var offset = 1; offset < 27; offset++){
var output = "";
for(var i in comb){
var ch = comb.charCodeAt(i);
ch = ch + offset > 122? 97 + ch + offset -122: ch+offset;
output += String.fromCharCode(ch);
}
console.log(offset + ':' + output);
{
"tag1": "明星",
"tag2": "刘诗诗",
"totalNum": 1314,
"start_index": 0,
"return_number": 30,
"data": [
{
"id": "4859542230",
"pn": 0,