Skip to content

Instantly share code, notes, and snippets.

@devk1d
devk1d / .md
Created September 5, 2017 10:55
IOS OC 创建各种 view

UIButton

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(100, 200, 100, 40)];
[btn setTitle:@"开始制作" forState:UIControlStateNormal];
[btn setBackgroundColor:[UIColor redColor]];
[self.view addSubview:btn];
@devk1d
devk1d / .md
Created September 5, 2017 10:52
IOS present view controller 横屏方法

在 controller 中加入以下代码

#pragma mark 强制横屏(针对present方式)
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeRight;
@devk1d
devk1d / js.js
Created June 2, 2017 11:17
JS 小代码
// isMobile
const getIsMobile = () => {
let isMobile = false;
try {
isMobile = !!((window.navigator && window.navigator.standalone) || navigator.userAgent.match('CriOS') || navigator.userAgent.match(/mobile/i));
} catch (ex) {
// continue regardless of error
}
@devk1d
devk1d / surge_main.conf
Created December 30, 2015 06:39
Config for surge.app
# This config file was created for myself (@shanskc). You may want to add or remove some rules to make efficient use of the Internet.
# Update: Rules and configuration tuning
# 从243开始Surge 加入了proxy和rule分离的配置Override,此文件为rules main.conf,在你的proxy中你可以引入此conf
# eg: 下面为你的proxy.conf,只需引入此main.conf 即可.
# -----START-----
# #!PROXY-OVERRIDE:main.conf
#
# [Proxy]
# Proxy = custom, ip, port, Methor, password
# -----END-----
@devk1d
devk1d / node-mysql
Last active August 29, 2015 14:19
node笔记.js
// Db.js
var conf = require('../config'),
mysql = require('mysql');
var Db = function() {
this.db = null;
this.table = '';
};
Db.prototype = {
<?
/**
*
* 根据经纬度计算距离 单位(米)
*/
function getdistance($lat1, $lng1, $lat2, $lng2) {
$r = 6378.137 * 1000; // 地球半径, 公里的话不用*1000
$dlat = deg2rad($lat2 - $lat1);
$dlng = deg2rad($lng2 - $lng1);
$a = pow(sin($dlat / 2), 2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * pow(sin($dlng / 2), 2);
//给据精度和纬度计算相距距离
function rad(d) {
return d * Math.PI / 180.0;
}
function GetDis(lat1, lng1, lat2, lng2) {
var radLat1 = rad(lat1);
var radLat2 = rad(lat2);
var a = radLat1 - radLat2;
var b = rad(lng1) - rad(lng2);
var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) +
@devk1d
devk1d / swift 笔记.swift
Last active August 29, 2015 14:14
swift 笔记
//1. 隐藏 Status Bar
override func prefersStatusBarHidden() -> Bool {
return true
}
//2. 圆角
view.layer.conerRadius = 10
view.clipsToBounds = true