Skip to content

Instantly share code, notes, and snippets.

View kimsk's full-sized avatar
💭
We have two lives, and the second begins when we realize we only have one.

Karlkim Suwanmongkol kimsk

💭
We have two lives, and the second begins when we realize we only have one.
View GitHub Profile
@kimsk
kimsk / WebPairCollectionTests.cs
Created March 24, 2013 18:40
Unit Tests for Callisto.OAuth.WebPairCollection.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using Callisto.OAuth;
namespace Callisto.Tests
{
[TestClass]
@kimsk
kimsk / AboutView.xaml
Created April 30, 2013 04:40
CaliburnSettings/CaliburnSettings/AboutView
<Page
x:Class="CaliburnSettings.AboutView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CaliburnSettings"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
@kimsk
kimsk / App.xaml.cs
Created April 30, 2013 04:46
CaliburnSettings/CaliburnSettings/App.xaml.cs Register AboutViewModel, SettingsService, and Command
protected override void Configure()
{
_container = new WinRTContainer();
_container.RegisterWinRTServices();
_container.PerRequest<MyPageViewModel>();
_container.PerRequest<AboutViewModel>();
var settings = _container.RegisterSettingsService();
protected override void Configure()
{
_container = new WinRTContainer();
_container.PerRequest<MainViewModel>()
.PerRequest<AboutViewModel>();
var viewSettings = new Dictionary<string, object>();
viewSettings.Add("headerbackground", new SolidColorBrush(Colors.Red));
@kimsk
kimsk / SplashScreen.xaml
Last active December 18, 2015 12:11
Windows 8 Splash screen sample, ใส่ dummy ProgressRing บน TextBlock จำลองการโหลด 1. หยุดไป 5 วินาทีให้เหมือนว่าโหลดอะไรบางอย่าง 2. ผมจำลองการโหลดข้อมูลนานๆ (คล้ายๆการ Thread.Sleep() บน .NET) เมื่อเสร็จแล้วเราก็ให้ไปโหลด MainPage โดยใช้ CoreDispatcher
<StackPanel Grid.Row="1" HorizontalAlignment="Center">
<ProgressRing Name="loadingSomething" IsActive="True" />
<TextBlock Style="{StaticResource BasicTextStyle}" TextWrapping="Wrap" TextAlignment="Center" Padding="5" HorizontalAlignment="Center">
The splash screen was dismissed and the image above was positioned using the splash screen API.
</TextBlock>
<Button x:Name="LearnMoreButton" Content="Learn More" HorizontalAlignment="Center" />
</StackPanel>
@kimsk
kimsk / twitterHack.cs
Created May 14, 2013 01:36
I add a urlWithParams which is a url with query parameter, for example, https://api.twitter.com/1.1/statuses/home_timeline.json?count=1 The full url will be used by HttpClient. However, when I am building signature string, I have to use the base url, https://api.twitter.com/1.1/statuses/home_timeline.json, and add the query parameter to the sigB…
private async void requestTwitterApi(string url)
{
string nonce = oAuthUtil.GetNonce();
string timeStamp = oAuthUtil.GetTimeStamp();
try
{
HttpClient httpClient = new HttpClient();
httpClient.MaxResponseContentBufferSize = int.MaxValue;
httpClient.DefaultRequestHeaders.ExpectContinue = false;
@kimsk
kimsk / MainPage.cs
Created May 14, 2013 01:37
เราจะได้ sender จาก PointerEventHandler ซึ่งเราสามารถนำมันมาหา index ได้ครับ ในตัวอย่างผมแสดงสามวิธีง่ายๆ: 1. เราอาจจะใช้ DataContext 2. หรือใช้ name หรือ ค่าอื่นๆ 3. หา index จาก array ที่เก็บ sender
public sealed partial class MainPage : Page
{
UIElement[] _uiElements;
public MainPage()
{
this.InitializeComponent();
var uiElements = new List<UIElement>();
for (int i = 0; i < 10; i++)
{
@kimsk
kimsk / saveFilesAsUTF8.ps1
Created May 15, 2013 05:04
Saving multiple files in a folder as UTF-8
$files = [IO.Directory]::GetFiles("C:\temp\files")
foreach($file in $files)
{
$content = get-content -path $file
$content | out-file $file -encoding utf8
}
@kimsk
kimsk / Win31days_29_001.cs
Created May 29, 2013 22:56
เรียนรู้ Windows Store app ภายใน 31 วัน | วันที่ 29 : Process Lifecycle Management 001
using System;
using Windows.Storage;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
 
namespace Day29_ApplicationLifecycle
{
    public sealed partial class MainPage : Page
    {
@kimsk
kimsk / Win8DevThaiVisualTreeHelper.MainPage.xaml.cs
Created June 3, 2013 19:32
VisualTreeHelper, VisualTreeHelperExtensions และ DataTemplate FrameworkElement.Loaded event http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.frameworkelement.loaded.aspx VisualTreeHelperExtensions http://winrtxamltoolkit.codeplex.com/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;