跳至主要内容

博文

目前显示的是 八月, 2017的博文

android lauch time fast app activity

资源加载 首先尽量避免将耗时操作直接写在Application的onCreate()中,可以采用异步或者IntentService的方式加载资源。 不要以静态变量的方式在Application中保存数据 画面渲染 为启动的Activity自定义一个Theme,指定一个闪屏画面相同的背景图片 < style name = "AppSplash" > < item name = "android:windowBackground" > @mipmap/splash_bg </ item > </ style > 将新的Theme应用到设置到AndroidManifest.xml中LauncherActivity中 < activity android:name = ".MainActivity" android:theme = "@style/AppWelcom" > < intent-filter > < action android:name = "android.intent.action.MAIN" /> < category android:name = "android.intent.category.LAUNCHER" /> </ intent-filter > </ activity > 在MainActivity中需要设置回原来的Theme public class MainActivity extends AppCompatActivity { @Override protected void onCreate( Bundle savedInstanceState) { setTheme( R .style. AppTheme ); super .onCreate(savedInstanceState); setContentView( R .lay

go spider example hello golang crawler

package main import ( "github.com/PuerkitoBio/goquery" "github.com/hu17889/go_spider/core/common/page" "github.com/hu17889/go_spider/core/pipeline" "github.com/hu17889/go_spider/core/spider" ) type MyPageProcesser struct { } func NewMyPageProcesser() *MyPageProcesser { return &MyPageProcesser{} } // Parse html dom here and record the parse result that we want to Page. // Package goquery (http://godoc.org/github.com/PuerkitoBio/goquery) is used to parse html. func (this *MyPageProcesser) Process(p *page.Page) { query := p.GetHtmlParser() query.Find("td div[class='flex-middle']").Each(func(i int, s *goquery.Selection) { println(s.Text()) }) } func (*MyPageProcesser) Finish() { } func main() { spider.NewSpider(NewMyPageProcesser(), "TaskName"). AddUrl("http://101.200.54.63/", "html").    // start url, html is the responce type ("html" or "json

python socket

//client import socket cl=socket.socket(socket.AF_INET,socket.SOCK_STREAM) cl.connect(("101.200.54.63",80)) cl.send("GET / HTTP/1.1\r\nHost: 101.200.54.63\r\n\r\n") rp=cl.recv(4096) print rp

css html hover on mouse over on active onmouse

<!DOCTYPE html> <html> <head> <title></title> <style type="text/css"> .one{ padding: 10px; cursor: pointer; box-shadow: 2px 2px 2px #aaa; } .one:hover{ box-shadow: 3px 3px 3px #aaa; z-index: 2; } .one:active{ box-shadow: 1px 1px 1px #aaa; } .one::selection{ background: #aaa; } </style> </head> <body style="font-family: sans-serif;"> <a href="new.html">hello</a> <span class="one">Hello</span> </body> </html>

css font ttf family set third party

<!DOCTYPE html> <html> <head>   <title></title>   <style type="text/css">     @font-face{       font-family: "YuWei";       src:url(YuWei.ttf) format("truetype");     }   </style> </head> <body style="font-family: 'YuWei'"> <h1>贺卡上的</h1> </body> </html>

javascript json

var text = ' { "sites" : [ ' + ' { "name":"Runoob" , "url":"www.runoob.com" }, ' + ' { "name":"Google" , "url":"www.google.com" }, ' + ' { "name":"Taobao" , "url":"www.taobao.com" } ]} ' ; obj = JSON . parse ( text ) ; document . getElementById ( " demo " ) . innerHTML = obj . sites [ 1 ] . name + " " + obj . sites [ 1 ] . url ;

javascript on respone done xmlhttpresponse ajax

<script>   function goLogin() { var xhr =new XMLHttpRequest() var fd=new FormData(document.getElementById("mForm")) xhr.onreadystatechange=function() { document.getElementById("result").innerHTML=xhr.responseText } xhr.open("POST", "http://127.0.0.1:8090/login", true) xhr.send(fd) } </script> </head> <body> <form id="mForm" action="http://127.0.0.1:8090/login" method="post" enctype="multipart/form-data"> <div class="flex-center flex-vertical top-gap"> <div class="unit-0"><input type="hidden" name="state" value="LOGIN"></div> <div class="unit-0">邮箱:<input type="text" name="email"></div> <div class="unit-0">密码:<input type="password" name="password"></div> <div class="unit-0

golang client http

package main import ( "bytes" "fmt" "io" "log" "mime/multipart" "net/http" "os" "path/filepath" ) // Creates a new file upload http request with optional extra params func newfileUploadRequest ( uri string , params map [ string ] string , paramName , path string ) (* http . Request , error ) { file , err := os . Open ( path ) if err != nil { return nil , err } defer file . Close () body := & bytes . Buffer {} writer := multipart . NewWriter ( body ) part , err := writer . CreateFormFile ( paramName , filepath . Base ( path )) if err != nil { return nil , err } _ , err = io . Copy ( part , file ) for key , val := range params { _ = writer . WriteField ( key , val ) } err = writer . Close () if err != nil { return nil , err } req , err :=

golang post get http client send

golang要请求远程网页,可以使用net/http包中的client提供的方法实现。查看了官方网站有一些示例,没有太全面的例子,于是自己整理了一下。 get请求 get请求可以直接http.Get方法,非常简单。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 func httpGet() {      resp, err := http.Get( "http://www.01happy.com/demo/accept.php?id=1" )      if err != nil {          // handle error      }        defer resp.Body.Close()      body, err := ioutil.ReadAll(resp.Body)      if err != nil {          // handle error      }        fmt.Println(string(body)) } post请求 一种是使用http.Post方式 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 func httpPost() {      resp, err := http.Post( "http://www.01happy.com/demo/accept.php" ,          "application/x-www-form-urlencoded" ,          strings.NewReader( "name=cjb" ))      if err != nil {          fmt.Println(err)      }        defer resp.Body.Close()      body, err := ioutil.ReadAll(resp.Body)