Skip to content

Instantly share code, notes, and snippets.

@tgnm
tgnm / platform agnostic view interface
Last active December 21, 2015 12:28
Platform agnostic view interface
public interface ILoginView
{
string Username { get; set; }
string Password { get; set; }
bool RememberMe { get; }
event Action Login();
event Action Exit();
}
@tgnm
tgnm / ConvertUnsafeString
Created January 30, 2014 15:37
Convert SecureString to String
public static string ConvertToUnsecureString(this SecureString securePassword)
{
if (securePassword == null)
throw new ArgumentNullException("securePassword");
IntPtr unmanagedString = IntPtr.Zero;
try
{
unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(securePassword);
return Marshal.PtrToStringUni(unmanagedString);
@tgnm
tgnm / ObservableStream
Created March 24, 2014 10:30
Observable stream that tries to control back pressure
public IObservable<byte[]> GetFileData(string filePath, IObservable<bool> continueReading)
{
AsyncSubject<byte[]> ret = new AsyncSubject<byte[]>();
Observable.Start(() =>
{
using (var stream = new MemoryStream())
{
int streamPos = 0;
byte[] buffer = new byte[128];
@tgnm
tgnm / keybase.md
Created August 4, 2014 17:37
keybase.md

Keybase proof

I hereby claim:

  • I am tiagomargalho on github.
  • I am mintycode (https://keybase.io/mintycode) on keybase.
  • I have a public key whose fingerprint is 3FBF DB77 A671 B734 0901 A076 8294 DC92 5159 767A

To claim this, I am signing this object:

2014-12-04 21:39:46.642 CouchbaseLiteiOSTests[917:409880] [Runner executing: Couchbase.Lite.Base64Test.TestDecode]
2014-12-04 21:39:46.644 CouchbaseLiteiOSTests[917:409880] [MonoTouch Version: 8.4.0]
2014-12-04 21:39:46.644 CouchbaseLiteiOSTests[917:409880] [Assembly: monotouch.dll (32 bits)]
2014-12-04 21:39:46.645 CouchbaseLiteiOSTests[917:409880] [GC: Boehm]
2014-12-04 21:39:46.645 CouchbaseLiteiOSTests[917:409880] [iPhone: iPhone OS v8.1.1]
2014-12-04 21:39:46.647 CouchbaseLiteiOSTests[917:409880] [Device Name: iPhone]
2014-12-04 21:39:46.652 CouchbaseLiteiOSTests[917:409880] [Device UDID: FFFFFFFF0D4EE2DC15C142D4AE92EA7739EF6AA8]
2014-12-04 21:39:46.654 CouchbaseLiteiOSTests[917:409880] [Device Locale: en_GB]
2014-12-04 21:39:46.659 CouchbaseLiteiOSTests[917:409880] [Device Date/Time: 04/12/2014 21:39:46]
2014-12-04 21:39:46.660 CouchbaseLiteiOSTests[917:409880] [Bundle: com.your-company.Couchbase.Lite.iOS.Tests]
@tgnm
tgnm / swift_choose_mutable
Last active August 29, 2015 14:26
CollectionType.Choose in Swift
extension CollectionType {
func choose<T>(transform:(elem:Self.Generator.Element) -> T?) -> [T] {
var final = [T]()
for item in self.enumerate() {
switch transform(elem:item.element) {
case let .Some(result): final.append(result)
case .None: ()
}
@tgnm
tgnm / gist:01a1fd552a12b15e9a86
Created July 29, 2015 22:20
Nuget fails to get UAP versions
Restoring NuGet packages...
To prevent NuGet from restoring packages during build, open the Visual Studio Options dialog, click on the Package Manager node and uncheck 'Allow NuGet to download missing packages during build.'
Unable to resolve System.ComponentModel.EventBasedAsync (≥ 4.0.10) for UAP,Version=v10.0.
Unable to resolve System.Diagnostics.Contracts (≥ 4.0.0) for UAP,Version=v10.0.
Unable to resolve System.Runtime.Serialization.Json (≥ 4.0.0) for UAP,Version=v10.0.
Unable to resolve System.Runtime.Serialization.Primitives (≥ 4.0.10) for UAP,Version=v10.0.
Unable to resolve System.ServiceModel.Http (≥ 4.0.10) for UAP,Version=v10.0.
Unable to resolve System.Text.Encoding.CodePages (≥ 4.0.0) for UAP,Version=v10.0.
Unable to resolve System.Numerics.Vectors.WindowsRuntime (≥ 4.0.0) for UAP,Version=v10.0.
Unable to resolve System.Private.DataContractSerialization (≥ 4.0.0) for UAP,Version=v10.0.
@tgnm
tgnm / MessageBus.cs
Last active August 4, 2018 22:21
System.Threading.Channels - MessageBus implementation
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Channels;
using System.Threading.Tasks;
namespace LWT
{
public class MessageBus
{
@tgnm
tgnm / docker-compose.yml
Created October 18, 2018 19:30
docker-compose: Grafana+InfluxDb
version: '3'
services:
influxdb:
image: influxdb:latest
container_name: influxdb
ports:
- "8083:8083"
- "8086:8086"
- "8090:8090"
@tgnm
tgnm / machine.js
Created January 4, 2020 08:58
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions