Skip to content

Instantly share code, notes, and snippets.

Avatar
🤔
Now thinking...

smallgeek smallgeek

🤔
Now thinking...
View GitHub Profile
@smallgeek
smallgeek / source.ts
Created Oct 29, 2019
プロパティを追跡されないようにする
View source.ts
unTracking<T>(source: T): T {
const target = {} as T;
Object.keys(source).forEach(key => {
Object.defineProperty(target, key, { configurable: false, value: (source as any)[key] } );
});
return target;
}
@smallgeek
smallgeek / NotifyNavigationBehavior.cs
Created Jul 13, 2017
nuits さんのコード (http://www.nuits.jp/entry/2016/09/26/221142) をベースに、画面遷移された初回だけ処理を実行させる
View NotifyNavigationBehavior.cs
using System;
using System.Runtime.CompilerServices;
using Xamarin.Forms;
namespace Smallgeek.Behaviors
{
public class NotifyNavigationBehavior : BindableBehavior<Page>
{
protected override void OnAttachedTo(Page bindable)
{
@smallgeek
smallgeek / App.xaml
Created May 18, 2017
MasterDetail でもメニューバーを表示するためのテンプレート試作
View App.xaml
<?xml version="1.0" encoding="utf-8" ?>
<prism:PrismApplication xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="clr-namespace:Prism.Unity;assembly=Prism.Unity.Forms"
x:Class="Smallgeek.App">
<Application.Resources>
<ResourceDictionary>
<ControlTemplate x:Key="NavigationMenuPageTemplate">
<Grid RowSpacing="0">
<Grid.RowDefinitions>
@smallgeek
smallgeek / BusyNotifierCommand.cs
Created Apr 28, 2017
2度押し防止コマンド試作
View BusyNotifierCommand.cs
using Reactive.Bindings.Notifiers;
using System;
using System.Threading.Tasks;
using System.Windows.Input;
namespace Reactive.Bindings
{
public class BusyNotifierCommand : BusyNotifierCommand<object>
{
public BusyNotifierCommand(Func<Task> execute)
@smallgeek
smallgeek / ExcelBuilder.fs
Created Mar 25, 2017
リアクティブプログラミングの擬似コードでよく見るやつ
View ExcelBuilder.fs
open System
open System.Reactive
open System.Reactive.Subjects
open System.Reactive.Linq
open Microsoft.FSharp.Control
open FSharp.Control.Reactive
open FSharp.Control.Reactive.Builders
open FSharp.Data
type BehaviorSubject<'a> with
@smallgeek
smallgeek / Partition.cs
Created Nov 30, 2016
効率のよくない List.partition
View Partition.cs
public static Tuple<IList<T>, IList<T>> Partition<T>(this IList<T> source, Func<T, bool> predicate)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (predicate == null) throw new ArgumentNullException(nameof(predicate));
var list = source.ToList();
return new Tuple<IList<T>, IList<T>>(
list.Where(x => predicate(x)).ToList(),
list.Where(x => predicate(x) == false).ToList());
}
@smallgeek
smallgeek / error.log
Created Nov 16, 2016
VS が Intellisense で落ちたときのエラー
View error.log
アプリケーション:devenv.exe
フレームワークのバージョン:v4.0.30319
説明: ハンドルされない例外のため、プロセスが中止されました。
例外情報:System.IndexOutOfRangeException
場所 Microsoft.CodeAnalysis.SymbolId+Parser.GetNthTypeParameter(Microsoft.CodeAnalysis.INamedTypeSymbol, Int32)
場所 Microsoft.CodeAnalysis.SymbolId+Parser.ParseTypeParameterSymbol(System.Collections.Generic.List`1<Microsoft.CodeAnalysis.ISymbol>)
場所 Microsoft.CodeAnalysis.SymbolId+Parser.ParseSymbolId(System.Collections.Generic.List`1<Microsoft.CodeAnalysis.ISymbol>)
場所 Microsoft.CodeAnalysis.SymbolId+Parser.ParseTypeSymbol()
場所 Microsoft.CodeAnalysis.SymbolId+Parser.ParseTypeArguments(System.Collections.Generic.List`1<Microsoft.CodeAnalysis.ISymbol>)
場所 Microsoft.CodeAnalysis.SymbolId+Parser.GetMatchingTypes(Microsoft.CodeAnalysis.INamespaceOrTypeSymbol, System.String, System.Collections.Generic.List`1<Microsoft.CodeAnalysis.ISymbol>)
View xor.fs
let xs1 = Set[Set[1;2;3]; Set[4;5;6]; Set[7;8;9]]
let xs2 = Set[Set[4;5;6]; Set[7;8;9]; Set[10;11;12]]
let union =
[xs1; xs2]
|> Set.unionMany
let intersect =
[xs1; xs2]
|> Set.intersectMany
@smallgeek
smallgeek / EnumerableExtensions.cs
Last active Jul 4, 2016
@gab_km さんと @wonderful_panda さんからの指摘を受け修正したもの。ついでに C# にした
View EnumerableExtensions.cs
public static IEnumerable<IReadOnlyList<T>> ChunkBySumIf<T>(this IEnumerable<T> source, Func<T, double> selector, Func<double, bool> predicate)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (selector == null) throw new ArgumentNullException(nameof(selector));
if (predicate == null) throw new ArgumentNullException(nameof(predicate));
using (var enumerator = source.GetEnumerator())
{
var values = new List<T>();
var acc = 0.0;
View Extensions.vb
<Extension>
Public Iterator Function ChunkBySumIf(Of T)(source As IEnumerable(Of T), selector As System.Func(Of T, Double), predicate As System.Func(Of Double, Boolean)) As IEnumerable(Of IEnumerable(Of T))
If source Is Nothing Then Throw New ArgumentNullException(NameOf(source))
If selector Is Nothing Then Throw New ArgumentNullException(NameOf(selector))
If predicate Is Nothing Then Throw New ArgumentNullException(NameOf(predicate))
Using enumerator = source.GetEnumerator()
Dim values As List(Of T) = Nothing