mysql 更改密码

mysql 更改密码
此时我们在命令行输入

1
mysql -u root -p

命令会提示没有commod not found,我们还需要将mysql加入系统环境变量。

1
2
3
4
5
6
(1).进入/usr/local/mysql/bin,查看此目录下是否有mysql,见pic6。
(2).执行vim ~/.bash_profile
在该文件中添加mysql/bin的目录,见pic7:
PATH=$PATH:/usr/local/mysql/bin
添加完成后,按esc,然后输入wq保存。
最后在命令行输入source ~/.bash_profile

现在你就可以通过mysql -u root -p登录mysql了,会让你输入密码,就是提示的默认密码
登录成功后,你可以通过下面的命令修改密码

1
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass')

python django新建项目

1 新建一个 django project

1
django-admin.py startproject project-name

一个 project 为一个项目,project-name 项目名称,改成你自己的,要符合Python 的变量命名规则(以下划线或字母开头)

2 新建 app

1
2
python manage.py startapp app-name
或 django-admin.py startapp app-name

一般一个项目有多个app, 当然通用的app也可以在多个项目中使用。

3 同步数据库

1
2
3
4
5
python manage.py syncdb

注意:Django 1.7.1及以上的版本需要用以下命令
python manage.py makemigrations
python manage.py migrate

这种方法可以创建表,当你在models.py中新增了类时,运行它就可以自动在数据库中创建表了,不用手动创建。

备注:对已有的 models 进行修改,Django 1.7之前的版本的Django都是无法自动更改表结构的,不过有第三方工具 south,详见 Django 数据库迁移 一节。

4 使用开发服务器
开发服务器,即开发时使用,一般修改代码后会自动重启,方便调试和开发,但是由于性能问题,建议只用来测试,不要用在生产环境。

1
2
3
4
5
6
7
8
9
10
11
python manage.py runserver

# 当提示端口被占用的时候,可以用其它端口:
python manage.py runserver 8001
python manage.py runserver 9999
(当然也可以kill掉占用端口的进程)

# 监听所有可用 ip (电脑可能有一个或多个内网ip,一个或多个外网ip,即有多个ip地址)
python manage.py runserver 0.0.0.0:8000
# 如果是外网或者局域网电脑上可以用其它电脑查看开发服务器
# 访问对应的 ip加端口,比如 http://172.16.20.2:8000

5 清空数据库

1
python manage.py flush

此命令会询问是 yes 还是 no, 选择 yes 会把数据全部清空掉,只留下空表。

6 创建超级管理员

1
2
3
4
5
6
python manage.py createsuperuser

# 按照提示输入用户名和对应的密码就好了邮箱可以留空,用户名和密码必填

# 修改 用户密码可以用:
python manage.py changepassword username

Swift 图片下载

Kingfisher

oc有个非常强大图片缓存处理的库SDWebImage,swift中现在也有个不错的图片处理的库—-Kingfisher

Kingfisher库下载图片默认是带缓存的

最简单的使用

1
2
import Kingfisher
imageView.kf_setImageWithURL(NSURL(string: "http//www.baidu.com.png")!)

配置 https

1
2
3
4
5
6
7
在info.plist里加上下面这段
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</plist>
去配置一个Dictionary类型的NSAppTransportSecurity 子item是Boolean类型NSAllowsArbitraryLoads value是YES

添加默认图

1
testImag.kf_setImageWithURL(NSURL(string: "http://your.png")!, placeholderImage: UIImage(named: "mrt"))

默认情况下Kingfisher使用url当做cache(缓存)的key。 不过你也可以自定义这个key 。

1
2
3
let URL = NSURL(string: "http://your.png")!
let resource = Resource(downloadURL: URL, cacheKey: "your_customized_key")
imageView.kf_setImageWithResource(resource)

Kingfisher 默认先从内存和硬盘搜 ,如果没找到才去URL down,当然你也可以强制它每次从URL down,忽略缓存

1
imageView.kf_setImageWithURL(NSURL(string: "your_image_url")!, placeholderImage: nil, optionsInfo: [.Options: KingfisherOptions.ForceRefresh])

下载和缓存系统

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
let downloader = KingfisherManager.sharedManager.downloader

// 修改超时时间
downloader.downloadTimeout = 5

let cache = KingfisherManager.sharedManager.cache

// 设置硬盘最大缓存50M ,默认无限
cache.maxDiskCacheSize = 50 * 1024 * 1024
// 设置硬盘最大保存3天 , 默认1周
cache.maxCachePeriodInSecond = 60 * 60 * 24 * 3

// 获取硬盘缓存的大小
cache.cache.calculateDiskCacheSizeWithCompletionHandler { (size) -> () in
println("disk size in bytes: \(size)")
}

//清理内存缓存
cache.clearMemoryCache()

// 清理硬盘缓存,这是一个异步的操作
cache.clearDiskCache()

// 清理过期或大小超过磁盘限制缓存。这是一个异步的操作
cache.cleanExpiredDiskCache()

回调

下载完成后

1
2
3
4
5
6
7
8
imageView.kf_setImageWithURL(NSURL(string: "your_image_url")!, 
placeholderImage: nil,
optionsInfo: nil,
progressBlock: { (receivedSize, totalSize) -> () in
println("Download Progress: \(receivedSize)/\(totalSize)") },
completionHandler: { (image, error, imageURL) -> () in
println("Downloaded and set!")
})

swift_ios_开发之UINavigationController的常用属性

Swift开发之UINavigationController的常用属性

1.导航栏是否隐藏

1
self.navigationController?.navigationBar.hidden = false

2.导航栏的最底部颜色设置

1
2
//backgroundColor 是最底下的color 
self.navigationController?.navigationBar.backgroundColor = UIColor.redColor()

3.导航栏的表层颜色,即首先看到的颜色

1
2
//barTintColor 是表层颜色
self.navigationController?.navigationBar.barTintColor = UIColor.grayColor()

4.导航栏中间标题title的颜色,大小,字体设置

1
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.blueColor(),NSFontAttributeName:UIFont(name: "Heiti SC", size: 24.0)!]

5.导航栏隐藏左边backitem,即leftbarbuttonitem

1
2
//完全隐藏backItem//
self.navigationItem.setHidesBackButton(true, animated: true)

6.导航栏leftbarbuttonitem的颜色设置

1
swiftself.navigationController?.navigationBar.tintColor = UIColor.whiteColor()

7.导航栏leftbarbuttonitem的字体,颜色,大小设置

1
self.navigationItem.leftBarButtonItem?.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.blueColor(),NSFontAttributeName: UIFont(name: "Chalkduster", size: 13)!], forState: UIControlState.Normal)

8.导航栏重新定义leftbarbuttonitem

1
2
3
4
5
6
7
8
9
10
//重新定义backItem,将覆盖原来的BackItem.与storyboard中拖入一个item,效果一样。都是覆盖原来的backitem。

//第一种代码定义方式
self.navigationItem.setLeftBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: self, action: "function"), animated: true)

//第二种代码定义方式
self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: self, action: "function")

//第三种代码定义的方式
self.navigationItem.setLeftBarButtonItem(UIBarButtonItem(title: "<Grandre", style: UIBarButtonItemStyle.Plain, target: self, action: "function"), animated: true)

9.导航栏设置成透明

1
2
3
4
//将导航栏设置成透明
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationController!.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true

swift - 状态栏

状态栏

1
2
3
4
 	//状态栏高度
let statusHeight = UIApplication.shared.statusBarFrame.height
//导航栏高度
let navigationHeight = self.navigationController?.navigationBar.frame.size.height

Swift - 隐藏状态栏(statusBar)的两种方法

1,全局设置

这种方法修改后,整个应用的所有视图都不显示状态栏。

(1)在 Info.plist 中添加如下配置

1
2
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

(2)在 General -> Deployment Info 中,将 Hide status bar 勾选。

2,在视图控制器中单独设置

这用方法适合于只隐藏部分页面的状态栏。我们在需要隐藏 statusbar 的 ViewController 中添加如下代码即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
import UIKit

class ViewController: UIViewController {

//隐藏状态栏
override var prefersStatusBarHidden: Bool {
return true
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}

swift代理delegate

实现代理传值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import UIKit

class ViewController: UIViewController,ChangeValueDelegate{

var btn = UIButton()

override func viewDidLoad() {
super.viewDidLoad()

self.view.backgroundColor = UIColor.whiteColor()

btn.setTitle("Change", forState:.Normal)
btn.backgroundColor = UIColor.blueColor()
btn.frame = CGRect(x: 100, y: 100, width: 100, height: 50)
btn.addTarget(self, action: #selector(change), forControlEvents: .TouchUpInside)
self.view.addSubview(btn)

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

// delegate 代理方法
func changeValue(value: String) {

btn.setTitle(value, forState: .Normal)
print("value:\(value)")

}
// 传值
func change(){

let vc = ChangeValueViewController()
vc.delegate = self
self.navigationController?.pushViewController(vc, animated: true)

}

}

协议

1
2
3
4
5
protocol ChangeValueDelegate {

func changeValue(value:String)

}

使用代理传值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class ChangeValueViewController: UIViewController {

var delegate:ChangeValueDelegate?

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
self.view.backgroundColor = UIColor.whiteColor()

self.delegate?.changeValue("ok")
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

UIView的常用属性和常用方法总结

UIView的常用属性和常用方法总结

1,UIView常用的一些属性如下:

1
2
3
4
5
6
7
8
9
frame:相对父视图的坐标和大小(x,y,w,h)
bounds:相对自身的坐标和大小,所以bounds的x和y永远为0(0,0,w,h)
center:相对父视图的中点坐标
transform:控制视图的放大缩小和旋转
superview:获取父视图
subviews:获取所有子视图
alpha:视图的透明度(0.0-1.0)
tag:视图的标志(Int类型,默认等于0),设置后,可以通过viewWithTag方法拿到这个视图
`

2,UIView的常用方法如下:

1
2
3
4
5
6
7
8
9
func removeFromSuperview():将视图从父视图中移除
func insertSubview(view:UIView, atIndex index:Int):指定一个位置插入一个视图,index越小,视图越往下
func exchangeSubviewAtIndex(index1:Int, withSubviewAtIndex index2:Int):将index1和index2位置的两个视图互换位置
func addSubview(view:UIView):添加视图到父视图
func insertSubview(view:UIView,belowSubview siblingSubview:UIView):在指定视图的下面插入视图
func insertSubview(view:UIVIew,aboveSubview siblingSubview:UIView):在指定视图上面插入视图
func bringSubviewToFront(view:UIView):把视图移到最顶层
func sendSubviewToBack(view:UIView):把视图移到最底层
func viewWithTag(tag:Int)->UIView?:根据tag值获取视图

ios-icon

根据一个1024的icon,生成所有规格的icon,同时创建好Contents.json文件,支持命令行。
主要原因是因为我每次用Phtosohop做完icon都要保存N种规格,烦死了,网上没有发现合适的工具,所以自己写了一个,不过我觉得肯定有这种工具,只不过我没有找到,好吧,算我重复造轮子了。
重点是针对Xcode5,旧版本也能用,但没有这么自动化,有用的拿去。

ios-icon

GitHub: https://github.com/conis/ios-icon