Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Manato Kameya Grabacr07

🏠
Working from home
View GitHub Profile
@Grabacr07
Grabacr07 / Ufcpp.cs
Created Dec 14, 2016
.NET 4.6 プロジェクトだとエラーになるけど、PCL だとエラーにならない構造体
View Ufcpp.cs
using System;
namespace Ufcpp
{
public struct Ufcpp
{
private readonly DateTimeOffset _dateTime;
public Ufcpp(DateTimeOffset dateTime)
{
@Grabacr07
Grabacr07 / save.cs
Last active May 10, 2016
Windows Spotlight の画像を縦横仕分けして保存するやつ (LINQPad 向け)
View save.cs
void Main()
{
var sourcePath = Environment.ExpandEnvironmentVariables(@"%LOCALAPPDATA%\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets");
var destinationPath = @"*** Your wallpaper folder ***";
var sourceDirectory = new DirectoryInfo(sourcePath);
if (!sourceDirectory.Exists)
{
$"Directory not found.".Dump();
return;
@Grabacr07
Grabacr07 / Counter.cs
Last active Aug 28, 2018
LINQPad で KanColleViewer のダウンロード数かぞえるやつ (要 Json.NET)
View Counter.cs
using (var client = new HttpClient())
{
var url = new Uri("https://api.github.com/repos/Grabacr07/KanColleViewer/releases");
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Grabacr07-LINQPad", "1.0"));
var result = Util.Cache(() => client.GetAsync(url).Result);
var json = await result.Content.ReadAsStringAsync();
var start = new DateTime(2015, 02, 01);
var end = start.AddYears(1).AddMilliseconds(-1.0);
@Grabacr07
Grabacr07 / MainWindowViewModel.cs
Created Aug 28, 2015
.NET Framework 4.5.1 以降でビルドする場合は CurrentMetricUnit と CurrentImperialUnit の set アクセサーは public にしてください
View MainWindowViewModel.cs
public class MainWindowViewModel : ViewModel
{
private double _metricValue, _imperialValue;
public ICommand ImperialUnitToMetric { get; private set; }
public ICommand MetricToImperialUnit { get; private set; }
public MetricUnit CurrentMetricUnit { get; set; }
public ImperialUnit CurrentImperialUnit { get; set; }
@Grabacr07
Grabacr07 / MainWindow.xaml
Created Aug 28, 2015
.NET Framework 4.5 だと動く。4.5.1 だと例外スローされる。
View MainWindow.xaml
<Window x:Class="WpfApplication38.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="200"
Height="100">
<TextBox Text="{Binding SampleText}" />
</Window>
@Grabacr07
Grabacr07 / MainWindow.xaml
Last active Jul 22, 2020
WPF の Thumb コントロールで Photoshop のナビゲーターを再現するやつ
View MainWindow.xaml
<Window x:Class="ThumbsScrollViewer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Width="1200"
Height="600">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
@Grabacr07
Grabacr07 / Blynclight.Console.cs
Created Nov 10, 2014
Blync を光らせて遊ぶ (コンソールから (テスト))
View Blynclight.Console.cs
class Program
{
static void Main(string[] args)
{
var controller = new BlyncLightController();
var numberOfDevices = controller.InitBlyncDevices();
if (numberOfDevices == 0) return;
try
@Grabacr07
Grabacr07 / GetRealSize.cs
Created Oct 31, 2014
Viewbox 内の要素が実際に描画されているサイズを計算するやつ (WPF)。Viewbox 内の要素 (real size を知りたいやつ) から Viewbox 外の要素 (このコードでは Window) にアクセスできれば、その座標系に変換してほげもげっと。たぶん。
View GetRealSize.cs
/// <summary>
/// Viewbox 内に配置された要素について、実際に描画されているサイズを計算します。
/// </summary>
public static Size GetRealSize(FrameworkElement target)
{
var min = target.TranslatePoint(new Point(0, 0), Window.GetWindow(target));
var max = target.TranslatePoint(new Point(target.ActualWidth, target.ActualHeight), Window.GetWindow(target));
return (Size)(max - min);
}
View fswallow.cs
static class Extensions
{
public static IEnumerable<T[]> ふぁぼツバめそっど<T>(this IEnumerable<T> source, Func<T, bool> predicate)
{
var buffer = new List<T>();
foreach (var value in source)
{
if (predicate(value))
{
@Grabacr07
Grabacr07 / ScrollBar.template.xaml
Last active Aug 29, 2015
ScrollBar の標準テンプレート (の抜粋)
View ScrollBar.template.xaml
<Grid x:Name="Bg"
SnapsToDevicePixels="true">
<Grid.ColumnDefinitions>
<ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}" />
<ColumnDefinition Width="0.00001*" />
<ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}" />
</Grid.ColumnDefinitions>
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
You can’t perform that action at this time.