Skip to content

Instantly share code, notes, and snippets.

View smallgeek's full-sized avatar
🤔
Now thinking...

すもぎ smallgeek

🤔
Now thinking...
View GitHub Profile
@smallgeek
smallgeek / source.ts
Created October 29, 2019 02:27
プロパティを追跡されないようにする
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 July 13, 2017 22:47
nuits さんのコード (http://www.nuits.jp/entry/2016/09/26/221142) をベースに、画面遷移された初回だけ処理を実行させる
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 08:25
MasterDetail でもメニューバーを表示するためのテンプレート試作
<?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 April 28, 2017 08:49
2度押し防止コマンド試作
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 March 25, 2017 14:29
リアクティブプログラミングの擬似コードでよく見るやつ
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 November 30, 2016 00:07
効率のよくない List.partition
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 November 16, 2016 03:08
VS が Intellisense で落ちたときのエラー
アプリケーション: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>)
@smallgeek
smallgeek / xor.fs
Created November 6, 2016 07:42
exclusive or
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 July 4, 2016 14:11
@gab_km さんと @wonderful_panda さんからの指摘を受け修正したもの。ついでに C# にした
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;
<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