program collections
Java
byte & 0xff
byte[] b = new byte[1];b[0] = -127;System.out.println("b[0]:"+b[0]+"; b[0]&0xff:"+(b[0] & 0xff));//output:b[0]:-127; b[0]&0xff:129計(jì)算機(jī)內(nèi)二進(jìn)制都是補(bǔ)碼形式存儲(chǔ):
b[0]: 補(bǔ)碼,10000001(8bit)
b[0]以int輸出:int(32bit),補(bǔ)位1。11111111 11111111 11111111 10000001(32bit)
和原數(shù)一致
b[0]&0xff:11111111 11111111 11111111 10000001(32bit) & 11111111 =
00000000 00000000 00000000 10000001
低精度轉(zhuǎn)成高精度數(shù)據(jù)類(lèi)型,有兩種擴(kuò)展方案。(1)補(bǔ)零擴(kuò)展 (2)符號(hào)位擴(kuò)展
對(duì)于正數(shù)兩種是一樣的。
使用補(bǔ)零擴(kuò)展能夠保證二進(jìn)制存儲(chǔ)的一致性,但不能保證十進(jìn)制值不變
使用補(bǔ)符號(hào)位擴(kuò)展能夠保證十進(jìn)制值不變,但不能保證二進(jìn)制存儲(chǔ)的一致性
對(duì)于有符號(hào)類(lèi)型,Java使用的是補(bǔ)符號(hào)位擴(kuò)展,這樣能保證十進(jìn)制的值不變
return break
break is used to exit (escape) the for-loop, while-loop, switch-statement that you are currently executing.
return will exit the entire method you are currently executing (and possibly return a value to the caller, optional).
inputstream byte[] to String
byte[] buffer = new byte[17];if (is != null) {int size = is.read(buffer);if(size > 0 ){String Str = new String(buffer,0,size);}}Stm32 send packet
byte[] packet = new byte[len];packet[0] = (byte) type;packet[1] = (byte) len;packet[2] = (byte) seq;packet[3] = (byte)(isreset?1:0);packet[4] = (byte) vx;packet[5] = (byte)(vx >>8);packet[6] = (byte) vy;packet[7] = (byte)(vy >>8 );// System.arraycopy(command.toDatas(), 0, packet, 3, command.getLen());int Seq = (datas[0]&0XFF);int vx = (datas[1]&0XFF) | ((datas[2])<<8));int Vy = ((datas[3]&0XFF) | ((datas[4])<<8));boolean Motostatel = ((datas[4] & (1 << 1))!=0);boolean Motostater = ((datas[4] & (1 << 2))!=0);System.arraycopy(Object src,int srcPos,Object dest,int destPos,int length)
src:源數(shù)組
srcPos:源數(shù)組起始位置
dest:目標(biāo)數(shù)組
destPos:目標(biāo)數(shù)組起始位置
length:長(zhǎng)度
Tips: src和dest是要可以互相轉(zhuǎn)換或是同類(lèi)型的數(shù)組
Tips:
可以自己復(fù)制自己
int[] src ={0,1,2,3,4,5,6}; System.arraycopy(src,0,src,3,3);// output:{0,1,2,0,1,2,6}生成一個(gè)長(zhǎng)度為length的臨時(shí)數(shù)組,將fun數(shù)組中srcPos
到srcPos+length-1之間的數(shù)據(jù)拷貝到臨時(shí)數(shù)組中,再執(zhí)行System.arraycopy(臨時(shí)數(shù)組,0,fun,3,3)
new Semaphore(0)
Semaphore semaphore = new Semaphore(0);try {semaphore.acquire();} catch (InterruptedException e) {e.printStackTrace();}//semaphore.release();初始化信號(hào)量為0,semaphore.acquire()線程會(huì)阻塞。直到semaphore.release()之后 信號(hào)量變?yōu)?。
mysql
1045 access denied for user 'root'@'localhost' using password yes
忘記localhost密碼,密碼錯(cuò)誤
step1,找到mysql安裝目錄下my.ini。在[mysql]下添加 skip-grant-tables
step2,重啟mysql服務(wù)
step3,以管理員身份運(yùn)行 cmd. 輸入mysql -u root -p,直接回車(chē)
step4,輸入use mysql
step5,mysql 5.6以前的,輸入U(xiǎn)PDATE mysql.user SET Password=PASSWORD('123456') WHERE User='root';
?
mysql 5.6以后的,輸入U(xiǎn)PDATE mysql.user SET authentication_string=PASSWORD('root') WHERE USER='root';
Android
權(quán)限
root
在linux系統(tǒng)中是只有root權(quán)限和普通權(quán)限,root即是最高權(quán)限。
Android獲取root其實(shí)和Linux獲取root權(quán)限一樣。Linux下獲取root權(quán)限的時(shí)候就是執(zhí)行sudo或者su。
Android本身就不想讓你獲得Root權(quán)限,大部分手機(jī)出廠的時(shí)候根本就沒(méi)有su這個(gè)程序。所以你想獲得Android的root權(quán)限,第一步就是要把編譯好的su文件拷貝到Android手機(jī)的/system/bin或者/system/xbin/目錄下。接下來(lái)你可以在Android手機(jī)的adb shell或者串口下輸入su了。
getColor() 過(guò)時(shí)
// 過(guò)時(shí) textView.setTextColor(getResources().getColor(R.color.text_color));textView.setTextColor(ContextCompat.getColor(this,R.color.text_color));Installation error:INSTALL_FAILED_UID_CHANGED
嘗試通過(guò)ADB刪除產(chǎn)生沖突的數(shù)據(jù)文件
adb rm -rf /data/data/<your.package.name>setHeight no use
當(dāng)設(shè)置的高度比原來(lái)默認(rèn)的高度要小時(shí),調(diào)整setHeight是不生效的。
editText=(EditText)findViewById(R.id.myEditText);// editText.setHeight(10); //不生效editText.getLayoutParams().height = 100;Installation error:INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
1.1 包名大寫(xiě)了
2.2 缺少AndroidManifest.xml文件
Error:Error converting bytecode to dex
1.1 包重復(fù)
2.2 build本身問(wèn)題, 只需要clean and rebuild 一下
EditText光標(biāo)顏色
EditText 有一個(gè)屬性 android:textCursorDrawable 用來(lái)控制光標(biāo)的顏色。android:textCursorDrawable="@null","@null"作用是讓光標(biāo)顏色和text color一樣
?
發(fā)現(xiàn)了以元素'd:skin'開(kāi)頭的無(wú)效內(nèi)容
把有問(wèn)題的devices.xml刪除,在Android SDK 里面的tool\lib 下找到devices.xml拷貝到那個(gè)文件夾。
?
finished with non-zero exit value 2
重復(fù)的jar包,刪除引用的包,同時(shí)刪除module的build.gradle文件的引用。
border
<?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"><solid android:color="#418bdc"/><corners android:radius="2dp"/><stroke android:width="2dp" android:color="#303f9f"/><padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" /> </shape>VideoView播放視頻無(wú)法全屏問(wèn)題
重寫(xiě)VideoView
import android.content.Context; import android.util.AttributeSet; import android.widget.VideoView;/*** Created by lijingnan on 12/04/2017.*/ public class CustomerVideoView extends VideoView {public CustomerVideoView(Context context) {super(context);}public CustomerVideoView(Context context, AttributeSet attrs) {super(context, attrs);}public CustomerVideoView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {// 其實(shí)就是在這里做了一些處理。int width = getDefaultSize(0, widthMeasureSpec);int height = getDefaultSize(0, heightMeasureSpec);setMeasuredDimension(width, height);} }退出程序
- KillProcess
Tips:android中所有的activity都在主進(jìn)程中,在Androidmanifest.xml中可以設(shè)置成啟動(dòng)不同進(jìn)程,Service不是一個(gè)單獨(dú)的進(jìn)程也不是一個(gè)線程。
當(dāng)你Kill掉當(dāng)前程序的進(jìn)程時(shí)也就是說(shuō)整個(gè)程序的所有線程都會(huì)結(jié)束,Service也會(huì)停止,整個(gè)程序完全退出。
- System.exit
Can't create handler inside thread that has not called Looper.prepare()
Handler對(duì)象與其調(diào)用者在同一線程中,如果在Handler中設(shè)置了延時(shí)操作,則調(diào)用線程也會(huì)堵塞。每個(gè)Handler對(duì)象都會(huì)綁定一個(gè)Looper對(duì)象,每個(gè)Looper對(duì)象對(duì)應(yīng)一個(gè)消息隊(duì)列(MessageQueue)。如果在創(chuàng)建Handler時(shí)不指定與其綁定的Looper對(duì)象,系統(tǒng)默認(rèn)會(huì)將當(dāng)前線程的Looper綁定到該Handler上。
在主線程中,可以直接使用new Handler()創(chuàng)建Handler對(duì)象,其將自動(dòng)與主線程的Looper對(duì)象綁定;在非主線程中直接這樣創(chuàng)建Handler則會(huì)報(bào)錯(cuò),因?yàn)锳ndroid系統(tǒng)默認(rèn)情況下非主線程中沒(méi)有開(kāi)啟Looper,而Handler對(duì)象必須綁定Looper對(duì)象。
1.手動(dòng)開(kāi)啟Looper,然后將其綁定到Handler對(duì)象上
final Runnable runnable = new Runnable() {@Overridepublic void run() {//執(zhí)行耗時(shí)操作try {Thread.sleep(2000);} catch (InterruptedException e) {e.printStackTrace();}} }; new Thread() {public void run() {Looper.prepare();new Handler().post(runnable);//在子線程中直接去new 一個(gè)handlerLooper.loop(); //這種情況下,Runnable對(duì)象是運(yùn)行在子線程中的,可以進(jìn)行聯(lián)網(wǎng)操作,但是不能更新UI} }.start();2.通過(guò)Looper.getMainLooper(),獲得主線程的Looper
final Runnable runnable = new Runnable() {@Overridepublic void run() {//執(zhí)行耗時(shí)操作try {Thread.sleep(2000);} catch (InterruptedException e) {e.printStackTrace();}} }; new Thread() {public void run() {new Handler(Looper.getMainLooper()).post(runnable);//這種情況下,Runnable對(duì)象是運(yùn)行在主線程中的,不可以進(jìn)行聯(lián)網(wǎng)操作,但是可以更新UI} }.start();xxx is not an enclosing class
- 一般出現(xiàn)在內(nèi)部類(lèi)中,若要?jiǎng)?chuàng)建內(nèi)部類(lèi)的實(shí)例,需要有外部類(lèi)的實(shí)例才行,或者是將內(nèi)部類(lèi)設(shè)置為靜態(tài)的,添加 static 關(guān)鍵字
there is no default constructor available in ...
子類(lèi)中使用了無(wú)參構(gòu)造方法,而它的父類(lèi)中至少有一個(gè)沒(méi)有無(wú)參的構(gòu)造方法。
- 如果一個(gè)類(lèi)沒(méi)有構(gòu)造方法,會(huì)有一個(gè)默認(rèn)的無(wú)參構(gòu)造方法。
如果顯示的定義了帶參構(gòu)造方法則默認(rèn)的無(wú)參構(gòu)造方法就會(huì)失效。
一個(gè)類(lèi)只要有父類(lèi),那么在它實(shí)例化的時(shí)候,一定是從頂級(jí)的父類(lèi)開(kāi)始創(chuàng)建
子類(lèi)使用無(wú)參構(gòu)造函數(shù)創(chuàng)建子類(lèi)對(duì)象時(shí),會(huì)去先遞歸調(diào)用父類(lèi)的無(wú)參構(gòu)造方法,這時(shí)候如果某個(gè)類(lèi)的父類(lèi)沒(méi)有無(wú)參構(gòu)造方法就會(huì)出錯(cuò)
錯(cuò)誤實(shí)例:
public class Parent{int aga;public Parent(int age){this.aga = age;}}public class Child extends Parent{public Child(){/** 默認(rèn)調(diào)用父類(lèi)的無(wú)參構(gòu)造方法 * super();*/}}如果子類(lèi)使用帶參參構(gòu)造函數(shù)創(chuàng)建子類(lèi)對(duì)象時(shí),沒(méi)有使用super先調(diào)用父類(lèi)的帶參構(gòu)造方法,這時(shí)默認(rèn)會(huì)調(diào)用父類(lèi)的無(wú)參構(gòu)造方法,如果父類(lèi)沒(méi)有也會(huì)報(bào)錯(cuò)
錯(cuò)誤實(shí)例:
public class Parent{int aga;public Parent(int age){this.aga = age;}}public class Child extends Parent{public Child(int age){/** 默認(rèn)調(diào)用父類(lèi)的無(wú)參構(gòu)造方法 * super();*/}}上述也可以在子類(lèi)調(diào)用父類(lèi)的有參構(gòu)造函數(shù)
public class Child extends Parent{public Child(int age){super(age);}}JFinal
javax.servlet.ServletContext
BUG :The type javax.servlet.ServletContext cannot be resolved. It is indirectly referenced from required
Solution: 把tomcat/lib目錄中的jsp-api.jar和servlet-api.jar導(dǎo)入到項(xiàng)目的web/lib目錄下。
?
cast
BUG :Jfinal Db.findFirst java.lang.Long cannot be cast to java.lang.Integer
Solution:return Db.findFirst(sql).getLong("count").intValue();
?
?
錯(cuò)誤: 編碼GBK的不可映射字符
BUG : eclipse導(dǎo)出javadoc時(shí)的錯(cuò)誤: 編碼GBK的不可映射字符
Solution:-encoding UTF-8 -charset UTF-8
JavaScript
數(shù)組刪除元素
?
var arr = [1,2,3,4];arr.splice(1,1);/*** Array(3)* 0:1* 1:3* 2:4*/var arr = [1,2,3,4];delete arr[1];/*** Array(3)* 0:1* 1:undefined* 2:3* 3:4*/delete arr[1],arr[1]變?yōu)閡ndefined,數(shù)組的索引也保持不變
不要使用包裝對(duì)象來(lái)創(chuàng)建原始類(lèi)型變量
在js中我們可以使用String()、Number()、Boolean()構(gòu)造函數(shù)來(lái)顯式的創(chuàng)建包裝對(duì)象
// String("test") , 一個(gè)字符串對(duì)象 // Number(5),一個(gè)數(shù)值對(duì)象 // Boolean(false),一個(gè)布爾對(duì)象// Don't do it!var x = new Boolean(false); if (x) {alert('hi'); // Shows 'hi'. }var x = Boolean(0); if (x) {alert('hi'); // This will never be alerted. } typeof Boolean(0) == 'boolean'; typeof new Boolean(0) == 'object';script文件異步加載
<script src="path/to/myModule.js" defer></script>
<script src="path/to/myModule.js" async></script>
<script>標(biāo)簽打開(kāi)defer或async屬性,腳本就會(huì)異步加載。渲染引擎遇到這一行命令,就會(huì)開(kāi)始下載外部腳本,但不會(huì)等它下載和執(zhí)行,而是直接執(zhí)行后面的命令。
- defer與async的區(qū)別是:defer要等到整個(gè)頁(yè)面在內(nèi)存中正常渲染結(jié)束(DOM 結(jié)構(gòu)完全生成,以及其他腳本執(zhí)行完成),才會(huì)執(zhí)行;async一旦下載完,渲染引擎就會(huì)中斷渲染,執(zhí)行這個(gè)腳本以后,再繼續(xù)渲染。一句話,defer是“渲染完再執(zhí)行”,async是“下載完就執(zhí)行”。另外,如果有多個(gè)defer腳本,會(huì)按照它們?cè)陧?yè)面出現(xiàn)的順序加載,而多個(gè)async腳本是不能保證加載順序的。
cookie
cookie只區(qū)分域名,不管端口
- cookie安全
1.1 httponly:設(shè)置了httponly屬性,無(wú)法通過(guò)腳本獲取到cookie信息
2.2 secure:設(shè)置了secure屬性,cookie只能通過(guò)https安全傳輸,并不會(huì)通過(guò)未加密的http連接發(fā)送
3.3 sameSite:目前只有chrome和firefox支持,用于定義cookie如果跨域發(fā)送
debug
debugger
可以在JavaScript手動(dòng)添加斷點(diǎn)
debugger;DOM
右擊DOM元素,'Force Element State',展開(kāi)子菜單可以看到幾種常見(jiàn)的偽類(lèi)::active, :hover, :focus, and :visited。可以調(diào)試偽類(lèi)。
右擊DOM元素,可以看到一個(gè)名為Break on的選項(xiàng),展開(kāi)有Subtree Modifications,Attributes Modifications以及Node Removal三個(gè)選項(xiàng)。(當(dāng)JS嘗試改變DOM元素時(shí),給元素添加的斷點(diǎn)便會(huì)觸發(fā)。)
a) Subtree Modifications,當(dāng)添加,改變,刪除子元素時(shí)觸發(fā)
b) Attributes Modifications,當(dāng)元素屬性被改變時(shí)觸發(fā)
c) Node Removal,當(dāng)移除元素時(shí)觸發(fā)
Audits
Audits可以檢查頁(yè)面的性能方面存在的問(wèn)題,并給出優(yōu)化意見(jiàn)
Jquery
Cannot read property 'msie' of undefined
原因是$.browser這個(gè)api從jQuery1.9開(kāi)始就正式廢除,js代碼里只要用到$.browser就會(huì)報(bào)這個(gè)錯(cuò)。
jQuery官方說(shuō)明
1.1 可以替換成1.9之前的版本
2.2 使用插件jQuery Migrate,這個(gè)插件會(huì)恢復(fù)在更新版本中廢棄的API
3.3 在jQuery文件之后,$.browser的代碼之前 加載以下代碼
jQuery.browser={};(function(){jQuery.browser.msie=false; jQuery.browser.version=0;if(navigator.userAgent.match(/MSIE ([0-9]+)./)){ jQuery.browser.msie=true;jQuery.browser.version=RegExp.$1;}})();$.ajax
data封裝不加入JSON.stringify(data),會(huì)變成字符串拼接,'name=vinxent&age=21',有點(diǎn)和get方法相像。
若使用JSON.stringify(data),則會(huì)傳輸json對(duì)象'{name;'vinxent', age:21}'。
所以,在一般場(chǎng)景來(lái)說(shuō),get方法無(wú)需JSON.stringify,post方法需要。
Jquery動(dòng)態(tài)綁定事件
//Jquery綁定事件$('.div').click(function(){});//Jquery動(dòng)態(tài)綁定事件$('.div').on('click',function(){});<-- 當(dāng)頁(yè)面動(dòng)態(tài)刷新時(shí),新加載的元素依然可以綁定事件 -->$(document).on('click','.div',function(){});Jquery on綁定hover事件
不能用on處理hover事件,因?yàn)镴query的hover事件是一個(gè)封裝的事件,不是真正的事件。
所以使用mouseenter和mouseleave來(lái)代替鼠標(biāo)懸浮和離開(kāi)事件。
$(document).on('mouseenter', '.div', function() { });$(document).on('mouseleave', '.div', function() { });Jquery獲取時(shí)間并且格式化
Date.prototype.format = function(format) {/** eg:format="YYYY-MM-dd hh:mm:ss";*/var o = {"M+" :this.getMonth() + 1, // month"d+" :this.getDate(), // day"h+" :this.getHours(), // hour"m+" :this.getMinutes(), // minute"s+" :this.getSeconds(), // second"q+" :Math.floor((this.getMonth() + 3) / 3), // quarter"S" :this.getMilliseconds()// millisecond}if (/(y+)/.test(format)) {format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));}for ( var k in o) {if (new RegExp("(" + k + ")").test(format)) {format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]: ("00" + o[k]).substr(("" + o[k]).length));}}return format; }var startTime = new Date().format("yyyy-MM-dd 00:00:00"); var endTime = new Date().format("yyyy-MM-dd hh:mm:ss");滾動(dòng)條滾動(dòng)底部
scrollTop([val]) 獲取匹配元素相對(duì)滾動(dòng)條頂部的偏移。
scrollLeft([val]) 獲取匹配元素相對(duì)滾動(dòng)條左側(cè)的偏移。
scrollHeight 滾動(dòng)條高度
Jquery size( )和length
size()是jQuery 提供的函數(shù),而 length是屬性。兩者的取值是一樣的。
頁(yè)面之間傳值
//頁(yè)面一location.href = "href2.html?id=3"; //頁(yè)面二var _url = document.URL;var _urlParam = _url.split('?')[1];var _value = _urlParam.split('=')[1];也可以使用jquery.params.js $.query.get("id");
### 靈活運(yùn)用三目運(yùn)算符
(_list.equipStatus ==1?"運(yùn)行中":(_list.repairStatus ==2?"維修中":"待確認(rèn)"))正確引用jQuery
2.借助第三方提供的CDN來(lái)引入jQuery,同時(shí)注意當(dāng)使用第三方CDN出現(xiàn)問(wèn)題時(shí),要引入本地的jQuery文件。
3.如果在</body>前引入script文件的話,就不用寫(xiě)document.ready了,因?yàn)檫@時(shí)執(zhí)行js代碼時(shí)DOM已經(jīng)加載完畢了。
優(yōu)化jQuery選擇器
<div id="nav" class="nav"> <a class="home" href="http://www.jquery001.com">jQuery學(xué)習(xí)網(wǎng)</a> <a class="articles" href="http://www.jquery001.com/articles/">jQuery教程</a> </div>如果我們選擇class為home的a元素時(shí),可以使用下邊代碼:
$('.home'); //1
$('#nav a.home'); //2
$('#nav').find('a.home'); //3
2.方法2,為要查找的元素添加了上下文,在這里變?yōu)椴檎襥d為nav的子元素,查找性能得到了很大提升。
3.方法3,使用了find方法,它的速度更快,所以方法三最好。
關(guān)于jQuery選擇器的性能優(yōu)先級(jí),ID選擇器快于元素選擇器,元素選擇器快于class選擇器。因?yàn)镮D選擇器和元素選擇器是原生的JavaScript操作,而類(lèi)選擇器不是。
緩存jQuery對(duì)象
緩存jQuery對(duì)象可以減少不必要的DOM查找,關(guān)于這點(diǎn)大家可以參考下緩存jQuery對(duì)象來(lái)提高性能。
// 糟糕 h = $('#element').height(); $('#element').css('height',h-20);// 建議 $element = $('#element'); h = $element.height(); $element.css('height',h-20);使用子查詢緩存的父元素
正如前面所提到的,DOM遍歷是一項(xiàng)昂貴的操作。典型做法是緩存父元素并在選擇子元素時(shí)重用這些緩存元素。
// 糟糕 var$container = $('#container'),$containerLi = $('#container li'),$containerLiSpan = $('#container li span'); // 建議 (高效) var$container = $('#container '),$containerLi = $container.find('li'),$containerLiSpan= $containerLi.find('span');精簡(jiǎn)jQuery代碼
一般來(lái)說(shuō),最好盡可能合并函數(shù)。
// 糟糕 $first.click(function(){$first.css('border','1px solid red');$first.css('color','blue'); }); // 建議 $first.on('click',function(){$first.css({'border':'1px solid red','color':'blue'}); });減少DOM操作
最小化DOM更新
重布局和重繪是WEB頁(yè)面中最常見(jiàn)的也是最昂貴的兩種操作。
當(dāng)改變樣式,而不改變頁(yè)面幾何布局時(shí),將會(huì)發(fā)生重繪。隱藏一個(gè)元素或者改變一個(gè)元素的背景色時(shí)都將導(dǎo)致一次重繪。
當(dāng)對(duì)頁(yè)面結(jié)構(gòu)進(jìn)行更新時(shí),將導(dǎo)致頁(yè)面重布局。
prop和attr方法
對(duì)于元素自身的固有屬性 使用 prop 對(duì)于自定義的屬性使用attr方法
例:獲取選中的checkbox的value值
$("input[type=checkbox]").each(function() {if(true == $(this).prop("checked")) {alert($(this).attr("value"));}});each遍歷
用each實(shí)現(xiàn)全選或是取消全選。
$("#selectAll").click(function() {if($("#selectAll").prop("checked")) {$("#selectAll input[type=checkbox]").each(function() {$(this).prop("checked", "true");});} else {$("#selectAll input[type=checkbox]").each(function() {$(this).removeAttr("checked");});}});layer.js
uploadify.js error placeholder element
這是因?yàn)閕nput 元素必須有id,并且用id初始化uploadify函數(shù)。否則就報(bào)錯(cuò)。
chart.js
Uncaught TypeError: Cannot read property 'length' of null
這個(gè)問(wèn)題是因?yàn)閖s代碼執(zhí)行的時(shí)候canvas還沒(méi)有被創(chuàng)建。可以將初始化圖表代碼片段放到window.onload后面
window.onload = function() {var ctx = document.getElementById("myChart");var lineChart = new Chart(ctx, {type: 'line',data: {labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],datasets: [{label: "2015",data: [10, 8, 6, 5, 12, 8, 16, 17, 6, 7, 6, 10]}]}}) }The problem is that when your code executes, the canvas has not been created yet. You should wrap your code inside a function and assign that function to window.onload event. You can see the sample code below.
Cannot read property 'transition' of null
Try to call mychart.update() after setting the new data... that solved the problem for me.
Browser
Slow network is detected. Fallback font will be used while loading
新版本的Chrome在網(wǎng)絡(luò)環(huán)境較差的時(shí)候會(huì)在控制臺(tái)輸出Slow network is detected. Fallback font will be used while loading,但有時(shí)會(huì)對(duì)調(diào)試造成不便,可以在chrome配置中禁用該項(xiàng):?
地址欄輸入chrome://flags/#enable-webfonts-intervention-v2,并設(shè)置為Disabled;重啟Chrome。
AngularJS
$sce
$sce is included by default starting with angular 1.2- so you don't need sanitize anymore in order to get $sce. So, with 1.2, you can pass $sce in as any other service. But make sure your angular is version 1.2 (in case you checked the sanitize version vs core).
獲取body元素
// $document 服務(wù)$document[0].bodyangular.element(document).find('body')防抖動(dòng)輸入
<body ng-controller="myCtrl"><div ng-app="App" ng-controller="Ctrl" class="app"><button ng-click="inc()">Add</button><span>{{ val }}</span></div><script>angular.module("App", []).controller("Ctrl", ['$scope', '$debounce', function($scope, $debounce) {$scope.shouldBeFocus = true;$scope.val = 0;$scope.inc = function() {$debounce(increase, 300);};var increase = function() {$scope.val++;}}]).factory('$debounce', ['$rootScope', '$browser', '$q', '$exceptionHandler',function($rootScope, $browser, $q, $exceptionHandler) {var deferreds = {},methods = {},uuid = 0;function debounce(fn, delay, invokeApply) {var deferred = $q.defer(),promise = deferred.promise,skipApply = (angular.isDefined(invokeApply) && !invokeApply),timeoutId, cleanup,methodId, bouncing = false;// check we dont have this method already registeredangular.forEach(methods, function(value, key) {if(angular.equals(methods[key].fn, fn)) {bouncing = true;methodId = key;}});// not bouncing, then register new instanceif(!bouncing) {methodId = uuid++;methods[methodId] = {fn: fn};} else {// clear the old timeoutdeferreds[methods[methodId].timeoutId].reject('bounced');$browser.defer.cancel(methods[methodId].timeoutId);}var debounced = function() {// actually executing? clean method bankdelete methods[methodId];try {deferred.resolve(fn());} catch(e) {deferred.reject(e);$exceptionHandler(e);}if(!skipApply) $rootScope.$apply();};timeoutId = $browser.defer(debounced, delay);// track id with methodmethods[methodId].timeoutId = timeoutId;cleanup = function(reason) {delete deferreds[promise.$$timeoutId];};promise.$$timeoutId = timeoutId;deferreds[timeoutId] = deferred;promise.then(cleanup, cleanup);return promise;}// similar to angular's $timeout canceldebounce.cancel = function(promise) {if(promise && promise.$$timeoutId in deferreds) {deferreds[promise.$$timeoutId].reject('canceled');return $browser.defer.cancel(promise.$$timeoutId);}return false;};return debounce;}]);;</script></body>this in AngularJS
angular.module("App", []).controller("Ctrl", function($scope) {// this controllerconsole.log("controller",this);$scope.foo = function() {// this scopeconsole.log("foo",this);};var foo2 = function() {// this windowsconsole.log("foo2",this);}$scope.foo();foo2();});angular.copy() angular.extend()
angular.copy(source, [destination]); // source: copy的對(duì)象. 可以使任意類(lèi)型, 包括null和undefined. destination:接收的對(duì)象 返回復(fù)制或更新后的對(duì)象
如果省略了destination,一個(gè)新的對(duì)象或數(shù)組將會(huì)被創(chuàng)建出來(lái);
如果提供了destination,則source對(duì)象中的所有元素和屬性都會(huì)被復(fù)制到destination中;
如果source不是對(duì)象或數(shù)組(例如是null或undefined), 則返回source;
如果source和destination類(lèi)型不一致,則會(huì)拋出異常。
angular.extend(destination, source);
復(fù)制src對(duì)象中的屬性到dst對(duì)象中. 支持多個(gè)src對(duì)象. 如果你不想改變一個(gè)對(duì)象,你可以把dst設(shè)為空對(duì)象{}: var object = angular.extend({}, object1, object2).
注意: angular.extend不支持遞歸復(fù)制.
Git
push 需要輸入用戶名和密碼
換成ssh方式
git remote -v // origin https://github.com/xxxxxx/xxxx.git (fetch) // origin https://github.com/xxxxxx/xxxx.git (push)git remote rm origingit remote add origin git@github.com:xxxxx/xxxx.gitgit push origingit默認(rèn)用notepad++ 打開(kāi)
git config --global core.editor "'D:\Notepad++\notepad++.exe' -multiInst -notabbar -nosession -noPlugin '$*'"npm
npm WARN saveError ENOENT: no such file or directory ... package.json
npm init -f
生成一個(gè)package.json
React
render(, document.body);
warning.js:36 Warning: render(): Rendering components directly into document.body is discouraged, since its children are often manipulated by third-party scripts and browser extensions. This may lead to subtle reconciliation issues. Try rendering into a container element created for your app.
ReactDOM.render(<Greeter />, document.getElementById('react_container'));轉(zhuǎn)載于:https://www.cnblogs.com/chenjy1225/p/9661237.html
總結(jié)
以上是生活随笔為你收集整理的program collections的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 焦旭超 201771010109《面向对
- 下一篇: 农行信用卡消费备用金怎么用?注意不能取现