Skip to content

Instantly share code, notes, and snippets.

View nuitsjp's full-sized avatar

Atsushi Nakamura nuitsjp

View GitHub Profile
@nuitsjp
nuitsjp / BitmapExtensions.cs
Created October 17, 2016 07:58
Convert System.Drawing.Bitmap to System.Windows.Media.ImageSource
[DllImport("gdi32.dll", EntryPoint = "DeleteObject")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeleteObject([In] IntPtr hObject);
public static ImageSource ToImageSource(this Bitmap bmp)
{
var handle = bmp.GetHbitmap();
try
{
return Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
@nuitsjp
nuitsjp / gist:4212f2dd384ebdeb4db89277940d3469
Created May 11, 2023 08:16
VSの発行時にTargetRuntimeにwin-x86やwinx64を指定したときにエラーになる際の詳細ログ
This file has been truncated, but you can view the full file.
ビルドを開始しました...
1>------ ビルド開始: プロジェクト: GettingStarted, 構成: Release Any CPU ------
2>------ 公開の開始: プロジェクト: GettingStarted, 構成: Release Any CPU ------
2>SDK 'Microsoft.NET.Sdk' を解決しています...
2>$(MSBuildExtensionsPath) で使用されている検索パスは C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild;$(MSBuildProgramFiles32)\MSBuild です
2>拡張パス C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild を使用して C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\$(MSBuildToolsVersion)\Microsoft.Common.props をインポートしようとしています
2>C:\Users\r23000425
2>$(MSBuildExtensionsPath) で使用されている検索パスは C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild;$(MSBuildProgramFiles32)\MSBuild です
2>拡張パス C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild を使用して C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportBefore\* をインポートしようとしています
2>17.0
@nuitsjp
nuitsjp / App.xaml.cs
Last active August 4, 2021 07:23
Xamarin.FormsでOnSleep・OnResumeをViewModelでハンドルする
public partial class App : Application
{
.....
protected override void OnSleep()
{
(MainPage.BindingContext as IApplicationLifecycle)?.OnSleep();
}
protected override void OnResume()
@nuitsjp
nuitsjp / pre-configuration.ps1
Created August 12, 2020 21:28
Scoop-Playbookのインストール前に必要だったこと
scoop install 7zip
scoop install sudo
scoop install dark
scoop install innounp
sudo Add-MpPreference -ExclusionPath 'C:\ProgramData\scoop'
sudo Add-MpPreference -ExclusionPath $home\scoop
Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1
@nuitsjp
nuitsjp / Enumに別名?をつけて表示する.cs
Last active March 13, 2020 21:45
Enumに別名?をつけて表示する
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Gender.Female.ToJapanese());
Console.ReadLine();
}
}
public enum Gender
@nuitsjp
nuitsjp / MockExtensions.cs
Created December 22, 2016 10:05
You can easily publish PropertyChanged events from the Moq.
public static class MockExtensions
{
public static IReturnsResult<T> NotifyPropertyChanged<T, TResult>(this Mock<T> mock, Expression<Func<T, TResult>> expression, TResult setupValue) where T : class, INotifyPropertyChanged
{
var memberExpression = expression.Body as MemberExpression;
if (memberExpression == null) throw new ArgumentException("expression.Body is not MemberExpression");
var returnResult = mock.Setup(expression).Returns(setupValue);
mock.Raise(m => m.PropertyChanged += null, new PropertyChangedEventArgs(memberExpression.Member.Name));
@nuitsjp
nuitsjp / GitHubCounter.cs
Last active March 21, 2019 14:48
Count download of GitHub release module.
using Newtonsoft.Json.Linq;
using System;
using System.Net.Http;
using System.Linq;
using System.Threading.Tasks;
public static class GitHubCounter
{
public static async Task CountDownload(string owner, string repository)
{
@nuitsjp
nuitsjp / GitHubCommitCounter.cs
Created March 21, 2019 14:29
Count commits to a specific owner's repository for a specific time period.
using Newtonsoft.Json.Linq;
using System;
using System.Net.Http;
using System.Linq;
using System.Threading.Tasks;
public static class GitHubCommitCounter
{
public static async Task Count(string owner, DateTime minDateTime)
{
@nuitsjp
nuitsjp / sample.cs
Created November 17, 2016 23:25
Use embedded sqlite database file in Xamarin.Forms
const string databaseFileName = "sqlite.db3";
// ルートフォルダを取得する
IFolder rootFolder = FileSystem.Current.LocalStorage;
// ファイルシステム上のDBファイルの存在チェックを行う
var result = await rootFolder.CheckExistsAsync(databaseFileName);
if (result == ExistenceCheckResult.NotFound)
{
// 存在しなかった場合、新たに空のDBファイルを作成する
var newFile = await rootFolder.CreateFileAsync(databaseFileName, CreationCollisionOption.ReplaceExisting);
// Assemblyに埋め込んだDBファイルをストリームで取得し、空ファイルにコピーする
@nuitsjp
nuitsjp / Bootstrapper.cs
Created November 2, 2016 07:09
PrismでViewとViewModelを別アセンブリにする場合のコードサンプル
ViewTypeToViewModelTypeResolver _resolver;
protected override void ConfigureViewModelLocator()
{
base.ConfigureViewModelLocator();
_resolver = new ViewTypeToViewModelTypeResolver(typeof(MainWindowViewModel).Assembly); // とりあえず適当なVMからAssembly取得して設定しておく
ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver(_resolver.Resolve);
}
public class ViewTypeToViewModelTypeResolver
{