Skip to content

Instantly share code, notes, and snippets.

View CarlLee's full-sized avatar

Carl Lee CarlLee

  • Chongqing China
View GitHub Profile
@CarlLee
CarlLee / async_conditioning.js
Last active August 29, 2015 11:57
checking multiple conditions asynchronously
var bools = {};
function check1(){
// do something
bools['check1'] = condition1;
finalChek();
}
function check2(){
// do other things
bool['check2'] = condition2);
@CarlLee
CarlLee / async_conditioning2.js
Last active August 29, 2015 12:09
async_conditioning with [async module](https://github.com/caolan/async)
var async = require('async');
var bools = {};
function check1(){
// do something
bools['check1'] = condition1;
}
function check2(){
// do other things
bools['check2'] = condition2;
@CarlLee
CarlLee / app.js
Created August 13, 2015 16:07
Angular.js example
angular.module('app', [])
.controller('ItemsCtrl', function($scope, $http){
$scope = $http.get('items.json').success(function(data){
$scope.items = data;
});
});
@CarlLee
CarlLee / gf.java
Last active August 29, 2015 14:28
if(she.getFaceValue() >= 90 &&
she.getBreastSize().compare(new BreastSize("36D")) >= 0){
this.sleepWith(she);
if(this.getHappiness() >= 60){
this.setGirlFriend(she);
int prevHappiness = this.getHappiness();
// Wait for 2 months
Thread.sleep(1000 * 3600 * 24 * 30 * 2);
if(this.getHappiness() - prevHappiness >= 15){
@CarlLee
CarlLee / callback.c
Created August 25, 2015 16:04
Demonstration of "callback function" in C
void *(mouse_listener)(int, int);
// Print coordinates if mouse is clicked
void on_mouse_clicked(int x, int y){
printf("%d, %d", x, y);
}
// Tell other code what to do when mouse is clicked by registering a event listener
void register_mouse_listener(void *(func_pointer)(int, int)){
mouse_listener = func_pointer;
@CarlLee
CarlLee / parallel_crawler.go
Last active August 31, 2015 00:50
An implementation of Go tour exercise, https://tour.golang.org/concurrency/9
package main
import (
"fmt"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
Fetch(url string) (body string, urls []string, err error)
package net.linni.webservice.controller.advice;
import net.linni.webservice.exception.AbstractRestAPIException;
import net.linni.webservice.exception.OperationFailureException;
import net.linni.webservice.exception.UnauthorizedOperationException;
import net.linni.webservice.model.Response;
import net.linni.webservice.util.ResponseCode;
import net.linni.webservice.util.ResponseFactory;
import org.springframework.beans.TypeMismatchException;
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 / 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);
});