小技巧(持续更新)

  • windows杀掉进程

C:\Users\j00113584>taskkill /F /PID 6848
成功: 已终止 PID 为 6848 的进程。

  • python中的布尔操作

      python中的布尔操作不支持&&,||,!,其布尔操作符为and,or,not

  • js中的undefined

       undefined表示 未定义:
(1)声明但未赋值的变量;
(2)未定义返回值的函数的返回值;
(3)未被赋值的函数参数
      判断一个变量是否是undefined,需要用严格等号(===),标准等号(==)会把null也认为是undefined

  • python中的对象属性访问

       python对象中的属性可以通过点访问符访问,点后直接跟属性名字,如:
x=obj.attr1
       但是跟变量名是不行的
var attr=attr1
x=obj.attr    //这种方式是不行的
       这时可借助 getattr函数
var attr=attr1
x=getattr(obj,attr)     //效果等同于obj.attr1

  • 鼠标滑过事件:hover

$(selector).hover(function(){
       //鼠标移到该组件上方
},function{
       //鼠标离开该组件
});

  • js中的多行文本赋值

var nm=function(){/*{% include "sources/dbfiles/inc/selmap.html" %}*/};//多行注释为了引入其他html文件,实现多行文本对js变量的赋值
var lines=new String(nm.toString());
lines=lines.substring(lines.indexOf("/*") + 2, lines.lastIndexOf("*/"));
$(".rightpane").html(lines);

  • Python输出不换行

#python 2
print x,
#python 3
print (x,end='')

  • JavaScript中的数据类型判断

typeof obj=='object')&&obj.constructor==Object,Array,String,Function,Date,Number
注意object要加引号。

  • <ul><li></li>...<li></li></ul>横着排列

ul li{float:left;}

  • 查看Django版本

python -c "import django; print(django.get_verision())"

16django其他信息查看:

其中-c的意思是通过python来执行后面的命令
-c <command>

Execute the Python code in commandcommand can be one or more statements separated by newlines, with significant leading whitespace as in normal module code.

If this option is given, the first element of sys.argv will be "-c" and the current directory will be added to the start of sys.path (allowing modules in that directory to be imported as top level modules).

其他信息查看
>>> dir(django)
['VERSION', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'get_version']

  • Django模板变量字符串连接

<span style="font-family: Arial, Helvetica, sans-serif;">{{"pre_"|add:name|add:"_post"}}</span>

  • Python中字符串类型判断:isinstance(obj, basestring)

basestring是str和unicode的超类(父类),也是抽象类,因此不能被调用和实例化,但可以被用来判断一个对象是否为str或者unicode的实例,isinstance(obj, basestring)等价于isinstance(obj, (str, unicode));

  • Python中函数作为参数时的默认值

如果想直接调用,如果没定义就不发生任何行为,可以这样写:cb=lambda:None。不能写lambda:pass或lambda:return,因为这样就相当于return pass或return return。不过python中有些内置函数参数的默认值是None,用的时候需要先判断一下。如:
def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,parse_int=None, parse_constant=None, object_pairs_hook=None, **kw),其中object_hook是函数参数

  • Django的内置标签:with

Caches a complex variable under a simpler name. This is useful when accessing an “expensive” method (e.g., one that hits the database) multiple times.

For example:

{% with total=business.employees.count %}
    {{ total }} employee{{ total|pluralize }}
{% endwith %}

The populated variable (in the example above, total) is only available between the {% with %} and {% endwith %} tags.

You can assign more than one context variable:

{% with alpha=1 beta=2 %}
    ...
{% endwith %}

Note

The previous more verbose format is still supported: {% with business.employees.count as total %}


  • js中的键盘响应事件

$(document).keydown(function(evt) {
   evt.which == 38     //左
   evt.which == 39     //上
   evt.which == 40     //右
   evt.which == 41     //下
});

  • select多选以及取值赋值

多选:<select multiple></select>
取值:val(),如果为多选结果为数组

赋值:val(values),如果为多选,values为数组

  • js关联数组

js中的关联数组其实也是一对象

    var arr=[];
    arr['one']=1;
    arr['two']=2;
    console.log(arr.length);   //0
    var dct={};
    dct['one']=1;
    dct['two']=2;
    console.log(dct.length);   //undefined

  • 动态加载js文件

$.ajax({
     url: "{{STATIC_URL}}plugin/jsRender/jsviews.js",
     async: false,
     dataType: "script"
});

  • python判断变量是否为字符串

def chkstr(s):
    try:s+''
    except:return False
    else:return True

  • document中的innerHTML/outerHTML

innerHTML:输出当前dom对象 包含的html
outerHTML:输出当前dom对象 对应的html

  • 注销hover事件

$(_this).unbind("mouseenter").unbind("mouseleave");

  • 从Postgresql中随即选取100条记录

select * from heatmap order by random() limit 100

  • 把数据从文件导入到Postgresql

copy heatmap from '/home/postgres/out.csv' delimiter '|';

  • google chrome 不能以root用户运行解决

exec -a "$0" "$HERE/chrome" "$@ --user-data-dir"

  • django的模板中没有!=,应该用not x == y来代替


  • 隐藏input边框

<span style="font-weight: bold; white-space: pre;">	</span>input:focus{
		outline: none;
	}
	input:-webkit-autofill {
		-webkit-box-shadow: 0 0 0px 1000px white inset;
	}

  • django模板遍历字典

{% for key,value in dicts.items %}
{% endfor %}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值