Skip to content

Instantly share code, notes, and snippets.

View jaredjenkins's full-sized avatar

Jared Jenkins jaredjenkins

  • Chronosphere
  • Chicago
View GitHub Profile
void OnUSDCurrencyExchange(long? transactionId, double usDollars, string purchasedCurrencyType, double amountPurchased){
if(!transactionId.HasValue){
//transactionId has no value so generate one
transactionId = GetRandomLong();
}
var currencies = new TransactionCurrency[2];
currencies[0] = TransactionCurrency.createReal(Math.Abs(usDollars) * -1, CurrencyType.USD);
currencies[1] = TransactionCurrency.createVirtual(Math.Abs(amountPurchased), purchasedCurrencyType);
Playnomics.instance.transaction(transactionId, TransactionType.CurrencyConvert, currencies, null, null, null);
@jaredjenkins
jaredjenkins / gist:5421868
Last active December 16, 2015 10:39
Unity HTTP Background Worker
while(taskQueue.Count > 0)
{
WebRequest httpRequest = null;
HttpWebResponse response = null;
Stream stream = null;
bool requestSucceeded = false;
var request = taskQueue.Dequeue();
request.Attempts ++;
try{
@jaredjenkins
jaredjenkins / ConcurrentQueue.cs
Last active November 13, 2017 00:00
Concurrent Queue for Unity
using System;
using System.Collections.Generic;
namespace PlaynomicsPlugin
{
internal class ConcurrentQueue<T>{
private readonly object syncLock = new object();
private Queue<T> queue;
@jaredjenkins
jaredjenkins / gist:5421919
Last active December 16, 2015 10:39
Polling for completed requests in MonoBehavior
void Update()
{
//the http worker has a method which returns (dequeues)
//an IEnumerable set of completed requests,
//internall it is enqueueing the completed requests
foreach(ApiResponse response in httpWorker.GetCompletedResponses())
{
if(response.Request.RequestCompleteHandler != null)
{
//we want to notify an object that we have completed the request
@jaredjenkins
jaredjenkins / gist:5421985
Created April 19, 2013 17:53
Parallel http requests in Unity
private IEnumerator ProcessRequests()
{
if(isProcessing || taskQueue.Count == 0){
yield break;
}
isProcessing = true;
//get a temp variable, otherwise we could be stuck in an infinite-loop (offline scenario)
int itemsToProcess = taskQueue.Count;
while(itemsToProcess > 0){
@jaredjenkins
jaredjenkins / crossdomain
Last active December 16, 2015 12:19
Unity Crossdomain
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*"/>
</cross-domain-policy>
@jaredjenkins
jaredjenkins / gist:5469066
Last active December 16, 2015 17:19
Initializing the Playnomics JavaScript API
<!-- Start Playnomics API -->
<script type="text/javascript">
_pnConfig={};
_pnConfig.userId="<USER-ID>";
var _pnAPIURL=document.location.protocol+"//js.a.playnomics.net/v1/api?a=<APPID>",
_pnAPI=document.createElement("script");
_pnAPI.type="text/javascript";_pnAPI.async=true;_pnAPI.src=_pnAPIURL;document.body.appendChild(_pnAPI);
</script>
<!-- End Playnomics API -->
brew update
brew versions FORMULA
cd `brew --prefix`
git checkout HASH Library/Formula/FORMULA.rb # use output of "brew versions"
brew install FORMULA
brew switch FORMULA VERSION
git checkout -- Library/Formula/FORMULA.rb # reset formula
## Example: Using Subversion 1.6.17
#
import logging
from termcolor import colored
class ColorLog(object):
colormap = dict(
debug=dict(color='grey', attrs=['bold']),
info=dict(color='white'),
warn=dict(color='yellow', attrs=['bold']),
static public bool JsonDataContainsKey(JsonData data,string key)
{
bool result = false;
if(data == null)
return result;
if(!data.IsObject)
{
return result;
}
IDictionary tdictionary = data as IDictionary;