Skip to content

Instantly share code, notes, and snippets.

@srkirkland
srkirkland / factualquery.cs
Created July 15, 2015 05:48
factual query using httpclient and oauth util
const string placeQuery = "http://api.v3.factual.com/t/places?geo={\"$point\":[38.544401,-121.742229]}";
using (var client = new HttpClient())
{
var header = OAuthUtil.GenerateHeader(new Uri(placeQuery), "KEY",
"SECRET", null, null, "GET");
client.DefaultRequestHeaders.Add("Authorization", header);
var res = client.GetAsync(placeQuery).Result;
res.EnsureSuccessStatusCode();
@srkirkland
srkirkland / factualresponse.cs
Created July 15, 2015 05:47
factual data return
public class FactualPlaceResponseContainer
{
public string Status { get; set; }
public FactualPlaceResponse Response { get; set; }
}
public class FactualPlaceResponse
{
[JsonProperty("included_rows")]
public int IncludedRows { get; set; }
@srkirkland
srkirkland / selectspan.sql
Created June 30, 2015 22:24
select timespan between each history status
WITH a AS
(
SELECT
rt.GiftID,
rt.ActedDate,
rt.Status,
rt.Description,
ROW_NUMBER() OVER(ORDER BY rt.GiftID, rt.ActedDate) AS RN
FROM Histories rt
)
@srkirkland
srkirkland / uiimageasset.cs
Created June 24, 2015 06:22
get asset info including location from uiimage
var refurl = obj.ValueForKey(UIImagePickerController.ReferenceUrl) as NSUrl;
//TODO: refurl is null on newly taken images
var lib = new ALAssetsLibrary();
lib.AssetForUrl(refurl, (ALAsset asset) => {
var loc = asset.Location;
}, (NSError error) => {
});
@srkirkland
srkirkland / rebuild.sql
Created May 20, 2015 22:02
helpful rebuild your indexes script
SELECT name, OBJECT_NAME(a.object_id), avg_fragmentation_in_percent,
'ALTER INDEX ' + b.name + ' ON ' + OBJECT_NAME(a.object_id) +' REBUILD WITH (STATISTICS_NORECOMPUTE = ON)' as command
FROM sys.dm_db_index_physical_stats (
DB_ID(N'PrePurchasing')
, OBJECT_ID('PrePurchasing')
, NULL
, NULL
, NULL) AS a
JOIN sys.indexes AS b
ON a.object_id = b.object_id AND a.index_id = b.index_id
@srkirkland
srkirkland / sqlstats.sql
Created May 20, 2015 22:01
overall sql stats for the last week
SELECT
avg(avg_cpu_percent) AS 'Average CPU Percentage Used',
max(avg_cpu_percent) AS 'Maximum CPU Percentage Used',
avg(avg_physical_data_read_percent) AS 'Average Physical IOPS Percentage',
max(avg_physical_data_read_percent) AS 'Maximum Physical IOPS Percentage',
avg(avg_log_write_percent) AS 'Average Log Write Percentage',
max(avg_log_write_percent) AS 'Maximum Log Write Percentage',
--avg(avg_memory_percent) AS 'Average Memory Used Percentage',
--max(avg_memory_percent) AS 'Maximum Memory Used Percentage',
avg(active_worker_count) AS 'Average # of Workers',
@srkirkland
srkirkland / frag.sql
Created May 20, 2015 00:05
database fragmentation
SELECT name, avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats (
DB_ID(N'PrePurchasing')
, OBJECT_ID('PrePurchasing')
, NULL
, NULL
, NULL) AS a
JOIN sys.indexes AS b
ON a.object_id = b.object_id AND a.index_id = b.index_id;
@srkirkland
srkirkland / camera.cs
Created May 6, 2015 02:09
request and check for camera access
var status = AVCaptureDevice.GetAuthorizationStatus (AVMediaType.Video);
if (status == AVAuthorizationStatus.Authorized) {
//yay
} else if (status == AVAuthorizationStatus.NotDetermined) {
AVCaptureDevice.RequestAccessForMediaType (AVMediaType.Video, (bool accessGranted) => {
if (accessGranted) {
//yay
} else {
//boo
@srkirkland
srkirkland / pulse.cs
Created February 24, 2015 08:45
upvote pulse animation
var pulseAnimation = CABasicAnimation.FromKeyPath ("transform.scale");
pulseAnimation.Duration = 0.15;
pulseAnimation.To = NSNumber.FromFloat(1.5f);
pulseAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
pulseAnimation.AutoReverses = true;
pulseAnimation.RepeatCount = 2;
_upvoteView.Layer.AddAnimation (pulseAnimation, "scalepulse");
@srkirkland
srkirkland / overlay.cs
Created February 19, 2015 08:09
rotation overlay
var centerImg = new UIImageView (UIImage.FromBundle ("findme_fab"));
centerImg.Frame = new RectangleF (
centerX - (centerImg.Frame.Width / 2) ,
centerY - centerImg.Frame.Height - 20 ,
centerImg.Frame.Width ,
centerImg.Frame.Height);
var animation = CABasicAnimation.FromKeyPath("transform.rotation.z");
animation.From = NSNumber.FromFloat (0.0f);
animation.To = NSNumber.FromFloat (2f * (float)Math.PI);
animation.Duration = 1f;