Skip to content

Instantly share code, notes, and snippets.

View victorchee's full-sized avatar
🎯
Focusing

Victor Chee victorchee

🎯
Focusing
View GitHub Profile
@victorchee
victorchee / iOSRadioGradient.m
Last active August 29, 2015 14:00
iOS放射渐进视图
CGContextRef context = UIGraphicsGetCurrentContext();
size_t num_locations = 2;
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
CGFloat components[8] = {1,1,1,1, // 中心颜色(r, g, b, alpha)
.2,.2,.2,1 // 边缘颜色};
CGFloat locations[2] = {0,1};
CGGradientRef gradient = CGGradientCreateWithColorComponents(rgb, components, locations, num_locations);
CGColorSpaceRelease(rgb);
CGRect bounds = self.bounds;
CGPoint center = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds)); // 中心发散渐进
@victorchee
victorchee / iOSLineGradient.m
Created April 21, 2014 08:27
iOS线性渐变视图
AGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = self.view.frame;
gradientLayer.colors = [NSArray arrayWithObjects:(id)baseColor.CGColor, (id)barColor.CGColor, nil];
[self.view.layer insertSublayer:gradientLayer atIndex:0];
@victorchee
victorchee / iOSAssociatedObject.m
Last active August 29, 2015 14:08
iOS关联对象
#import "ViewController.h"
#import <objc/runtime.h>
@interface ViewController () <UIAlertViewDelegate>
@end
static void *MyAlertViewKey = "MyAlertViewKey";
@implementation ViewController
@victorchee
victorchee / Raspberry_Door.py
Last active August 29, 2015 14:13
Raspberry Door
import RPi.GPIO as GPIO
import pycurl, json
from StringIO import StringIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(25, GPIO.OUT)
appID = "54bc5b49a4c48a3d5bf22c4c"
appSecret = "a55bc3eb578bcd5d9065d24f83fa3219"
@victorchee
victorchee / raspberryflask.py
Created January 28, 2015 13:16
树莓派中使用Flask实现查看CPU和GPU温度,捕获摄像头图像并展示。
from flask import Flask, jsonify, request, render_template, url_for, send_from_directory, redirect
2 import temperature
3 import camera
4 app = Flask(__name__)
5 app.config['UPLOAD_FOLDER'] = 'static'
6
7 @app.route("/")
8 def index(): pass
9
10 @app.route("/temperature")
@victorchee
victorchee / camera.py
Created January 28, 2015 13:23
Python控制摄像头获取当前图像。
import pygame
2 import pygame.camera
3 #from pygame.locals import *
4
5 # initialize
6 pygame.init()
7 pygame.camera.init()
8
9 camera = pygame.camera.Camera("/dev/video0", (640, 480))
10
@victorchee
victorchee / temperature.py
Created January 28, 2015 13:25
树莓派获取当前CPU和GPU温度。
1 import commands
2
3 def get_cpu_temperature():
4 temperatureFile = open("/sys/class/thermal/thermal_zone0/temp")
5 cpu_temperature = temperatureFile.read()
6 temperatureFile.close()
7 return float(cpu_temperature)/1000
8
9 def get_gpu_temperature():
10 gpu_temperature = commands.getoutput('/opt/vc/bin/vcgencmd measure_temp').replace('temp=', '').replace('\'C', '')
func p_setupTextLayer(text: String) -> CAShapeLayer {
var letters = CGPathCreateMutable()
let font = CTFontCreateWithName("Helvetica-Bold", 72, nil)
let attrs = [kCTFontAttributeName: font]
var attrString = NSAttributedString(string: text, attributes: attrs)
let line = CTLineCreateWithAttributedString(attrString)
let runArray = CTLineGetGlyphRuns(line)
@victorchee
victorchee / Reachability.m
Created April 15, 2015 06:15
Get network status in iOS7
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
typedef enum : NSInteger {
NotReachable = 0,
ReachableViaWiFi,
ReachableVia2G,
ReachableVia3G,
ReachableVia4G,
ReachableViaWWAN
} NetworkStatus;
//
// MJGImageLoader.h
// MJGFoundation
//
// Created by Matt Galloway on 18/01/2012.
// Copyright 2012 Matt Galloway. All rights reserved.
//
/**
* Example usage: