Skip to content

Instantly share code, notes, and snippets.

View benbahrenburg's full-sized avatar

Ben Bahrenburg benbahrenburg

View GitHub Profile
@seckincengiz
seckincengiz / ExampleUsage.swift
Last active July 10, 2018 19:21 — forked from s-aska/Keychain.swift
Swift Keychain class ( supported Xcode 8.1 Beta and IOS 10.1 ) [swift3]
import UIKit
let scoresStringArray : [String] = ["Mike","Tom","Bily"]
let scoresDataArray = NSKeyedArchiver.archivedData(withRootObject: scoresStringArray)
//Save data
_ = Keychain.save(key: "scoresKey", data: scores)
//Load data
if Keychain.load(key: "scoresKey") != nil{
@marshall
marshall / app.js
Created January 27, 2011 23:07
Sample proguard configuration for a basic Titanium App
var win = Ti.UI.createWindow({
backgroundColor: 'white',
top: 0, left: 0, right: 0, bottom: 0,
layout: "vertical"
});
var button = Ti.UI.createButton({
title: "click me"
});
win.add(button);
@preble
preble / DateRange.swift
Last active July 16, 2019 14:06
Experimenting with creating a SequenceType for iterating over a range of dates. Blogged here: http://adampreble.net/blog/2014/09/iterating-over-range-of-dates-swift/
import Foundation
func > (left: NSDate, right: NSDate) -> Bool {
return left.compare(right) == .OrderedDescending
}
extension NSCalendar {
func dateRange(startDate startDate: NSDate, endDate: NSDate, stepUnits: NSCalendarUnit, stepValue: Int) -> DateRange {
let dateRange = DateRange(calendar: self, startDate: startDate, endDate: endDate, stepUnits: stepUnits, stepValue: stepValue, multiplier: 0)
return dateRange
@BrandonLWhite
BrandonLWhite / gist:235fa12247f6dc827051
Created October 2, 2014 17:28
Import .cer and .pvk certificate files programmatically in C# for use with `netsh http add sslcert`
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;
var abyPublicKey = AssemblyUtility.GetEmbeddedFileAsByteArray("WebServer.SslCertificate.cer");
var abyPrivateKey = AssemblyUtility.GetEmbeddedFileAsByteArray("WebServer.SslCertificate.pvk");
var certificate = new X509Certificate2(abyPublicKey, string.Empty,
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
var cspParams = new CspParameters
{
@dawsontoth
dawsontoth / app.js
Created April 16, 2012 19:36
Pullable Left Menu
var win = Ti.UI.createWindow({
backgroundColor: '#333'
});
var menuWidth = 200;
var container = Ti.UI.createScrollView({
disableBounce: false,
horizontalBounce: true,
contentWidth: Ti.Platform.displayCaps.platformWidth + menuWidth
@viezel
viezel / app.js
Last active June 15, 2020 19:13
Codebird for Appcelerator Titanium. Using the Twitter API 1.1
// This is an example of use.
// Here we use the new Bearer Token thats make it possible to get tweets without user login
// More info on Bearer here: https://dev.twitter.com/docs/auth/application-only-auth
// Full Codebird API is here: https://github.com/mynetx/codebird-js
var Codebird = require("codebird");
var cb = new Codebird();
cb.setConsumerKey('CONSUMER_KEY', 'CONSUMER_SECRET_KEY');
var bearerToken = Ti.App.Properties.getString('TwitterBearerToken', null);
@kareman
kareman / Queue.swift
Last active July 31, 2020 19:16
A standard queue (FIFO - First In First Out) implemented in Swift. Supports simultaneous adding and removing, but only one item can be added at a time, and only one item can be removed at a time. Using the "Two-Lock Concurrent Queue Algorithm" from http://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html#tlq, without the locks.
//
// Queue.swift
// NTBSwift
//
// Created by Kåre Morstøl on 11/07/14.
//
// Using the "Two-Lock Concurrent Queue Algorithm" from http://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html#tlq, without the locks.
// should be an inner class of Queue, but inner classes and generics crash the compiler, SourceKit (repeatedly) and occasionally XCode.
@revskill10
revskill10 / lopmonhoc.js.jsx
Created January 22, 2014 09:25
Integrate Datatable with React.js
/** @jsx React.DOM */
var LopMonHoc = React.createClass({
getInitialState: function(){
return {data: []}
},
loadData: function(){
$.ajax({
url: '/daotao/lops',
success: function(data){
@kgn
kgn / jquery.flipbook.js
Created November 29, 2010 07:22
jQuery plugin to display an animated image sequence.
//By David Keegan
//InScopeApps.com
//http://inscopeapps.com/demos/flipbook/
(function($){
$.fn.flipbook = function(options){
options = $.extend({
'start': 0, //start frame
'end': 100, //end frame, must be greater then start
'step': 1, //number of frames to step over while animating
@osteslag
osteslag / Metadata.swift
Created August 14, 2018 16:55
Swift Playground for updating an image file’s metadata without re-processing the image.
// Adapted from Apple's Tech Note, [Modifying Image Metadata Without Recompressing Image](https://developer.apple.com/library/archive/qa/qa1895/_index.html).
import Cocoa
import ImageIO
let url = URL(fileURLWithPath: "/path/to/file.tiff")
guard let imageSource = CGImageSourceCreateWithURL(url as CFURL, nil) else { fatalError("Cannot create URL") }
guard var properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as? Dictionary<CFString, Any> else { fatalError("Cannot get image properties") }
properties[kCGImageDestinationDateTime] = Date()