Skip to content

Instantly share code, notes, and snippets.

View aspyct's full-sized avatar

Antoine d'Otreppe aspyct

View GitHub Profile
@aspyct
aspyct / workaround.php
Created August 22, 2012 16:10
The most undebuggable PHP snippet ever
<?php
define("true ", false);
function doIt() {
define(" false", true);
define("maybe", rand() & 1);
}
function  ($stupid="clever") {
if (assert_value($stupid)) {
@aspyct
aspyct / BundleSerializationExtensions.cs
Created February 28, 2017 14:41
Android/Xamarin Bundle serialization
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Android.OS;
namespace Serialization
{
public static class BundleSerializationExtensions
{
public static void PutObject(this Bundle self, string key, object obj)
@aspyct
aspyct / RecycledViewPool.cs
Created March 3, 2017 09:34
Reusable Xamarin.Android RecycledViewPool
class RecycledViewPool
{
public delegate ViewHolder Factory(ViewGroup parent, int viewType);
// A stack has a O(1) add/remove, so better than a list
Dictionary<int, Stack<ViewHolder>> pool;
Factory factory;
public RecycledViewPool(Factory factory)
{
@aspyct
aspyct / Project.csproj
Created March 17, 2017 20:38
Install non-netstandard libs in a .net core project
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PackageTargetFallback>portable-net45+win8+wp8+wpa81</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Compilers" Version="2.0.0" />
@aspyct
aspyct / State.cs
Last active March 17, 2017 23:18
Generate a .immutable.cs containing constructors and Derive() method for an immutable c# class.
using System;
using Monad;
namespace NightOut.Core.ViewModel.CheckIn.LocationSelector
{
[Serializable]
partial class State
{
public readonly Maybe<string> longitude = Nothing<string>.Default;
public readonly Maybe<string> latitude = Nothing<string>.Default;
@aspyct
aspyct / AssemblyInfo.cs
Created March 29, 2017 20:26
Show internal classes to the test assembly
// Note: this also works for netstandard libraries. Just create the file and compile it.
using System.Runtime.CompilerServices;
[assembly:InternalsVisibleTo("NightOut.Core.Test")]
@aspyct
aspyct / Project.Droid.csproj
Created April 13, 2017 18:10
Increase java heap size while deploying Xamarin.Android project on device
+ <PropertyGroup>
+ <JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
+ </PropertyGroup>
@aspyct
aspyct / Project.Core.csproj
Created April 13, 2017 19:48
Enable debugging in .netstandard libraries for Xamarin
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugType>Full</DebugType>
+ </PropertyGroup>
@aspyct
aspyct / heap.rb
Created August 22, 2012 19:42
Binomial heap (priority queue) implementation in ruby
class Heap
def initialize
# @elements is an array representing the tree
# for each i:
# parent => @elements[i / 2]
# left => @elements[i * 2]
# right => @elements[i * 2 + 1]
@elements = []
end
public static class BundleExtensions
{
const string SERIALIZED_KEY = "__JSONSERIALIZED__";
static List<IMapItem> typesMapping;
//TODO: put in order of preference (cf string/charseq , serializable/parcelable, ...) because the for loop will stop at the first recognized type
static BundleExtensions() {
typesMapping = new List<IMapItem>{
new TypeMap<IBinder> ((b, i, v) => b.PutBinder(i, v), (b, i) => b.GetBinder(i)),