Skip to content

Instantly share code, notes, and snippets.

@lloydsheng
lloydsheng / UIButton-Stretchable-Image-Background.m
Last active March 19, 2018 08:12
设置UIButton的拉伸背景
UIImage *normalImage = [[UIImage imageNamed:@"blog_shopping_button.png"]
stretchableImageWithLeftCapWidth:80 topCapHeight:24];
UIImage *selectedImage = [[UIImage imageNamed:@"blog_shopping_button_selected.png"]
stretchableImageWithLeftCapWidth:80 topCapHeight:24];
@lloydsheng
lloydsheng / iOS-Custom-Tabbar.m
Last active March 19, 2018 08:13
一端iOS5.0以上订制UITabbar的代码
[self.tabBar setSelectionIndicatorImage:[UIImage imageNamed:@"tab-bar_highlighted.png"]];
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
RGB(187, 187, 187), UITextAttributeTextColor,
[UIFont systemFontOfSize:10], UITextAttributeFont,
nil]
forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
RGB(153, 210, 249), UITextAttributeTextColor,
@lloydsheng
lloydsheng / Python-Timestamp.py
Last active March 19, 2018 08:16
python date to timestamp
import time
import datetime
now = datetime.datetime.now()
time.mktime(now.timetuple())
@lloydsheng
lloydsheng / ipin.py
Created February 11, 2014 14:58 — forked from urielka/ipin.py
#---
# iPIN - iPhone PNG Images Normalizer v1.0
# Copyright (C) 2007
#
# Author:
# Axel E. Brzostowski
# http://www.axelbrz.com.ar/
# [email protected]
#
# References:
@lloydsheng
lloydsheng / gist:10440385
Created April 11, 2014 04:07
monit snmp with snmpwalk
import os
import time
import datetime
command = 'snmpwalk -v3 -l NoAuthNoPriv -u cisco 192.168.1.1 "ifInOctets.10"'
r = os.popen(command).read()
last_octes = r.replace("\n", "").split(" ")[-1]
last_octes = int(last_octes)
per = 3
while (True):
let centerLocation = CLLocationCoordinate2D(latitude: 0, longitude: 66)
let styleURL = URL(string: "mapbox://styles/lloydsheng/cjdjzspzq5b4b2sobtqxeooll")
let camera = MGLMapCamera(lookingAtCenter: centerLocation, fromDistance: 100, pitch: 0, heading: 0)
let options = MGLMapSnapshotOptions(styleURL: styleURL, camera: camera, size: CGSize(width: 300, height: 300))
let snapShooter = MGLMapSnapshotter(options: options)
snapShooter.start { (shooter, error) in
let image = shooter?.image;
print("\(image)")
}
UIGraphicsBeginImageContextWithOptions(snapshotView.bounds.size, true, 0.0)
snapshotView.drawHierarchy(in: snapshotView.bounds, afterScreenUpdates: true)
let snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
print("\(snapshotImage.debugDescription)")
- (MKMapRect)visibleMapRect {
MGLCoordinateBounds bounds = self.mapboxMapView.visibleCoordinateBounds;
MKMapPoint sw = MKMapPointForCoordinate(bounds.sw);
MKMapPoint ne = MKMapPointForCoordinate(bounds.ne);
double x = sw.x;
double y = ne.y;
double width = ne.x - sw.x;
double height = sw.y - ne.y;
import UIKit
import Mapbox
class CustomPointAnnotation : MGLPointAnnotation {
}
class IconAnnotationView: MGLAnnotationView {
var iconView = UIImageView(frame: CGRect(x: 0, y: 0, width: 60, height: 60))
[
[214.0,291.0],
[290.0,426.0],
[130.0,234.0],
[41.0,192.0],
[273.0,393.0],
[53.0,50.0],
[61.0,337.0],
[251.0,296.0],
[264.0,232.0],