Skip to content

Instantly share code, notes, and snippets.

@draco1023
draco1023 / ImageToDataUrl.cs
Created December 18, 2015 01:28
Convert image to data url
public static string GetDataURL(string imgFile)
{
return "<img src=\"data:image/"
+ Path.GetExtension(imgFile).Replace(".","")
+ ";base64,"
+ Convert.ToBase64String(File.ReadAllBytes(imgFile)) + "\" />";
}
@draco1023
draco1023 / 0_reuse_code.js
Created January 14, 2016 01:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@draco1023
draco1023 / TextFileEncodingDetector.cs
Created March 11, 2016 00:43 — forked from TaoK/TextFileEncodingDetector.cs
Simple class to automatically detect text file encoding, with English-biased "best guess" heuristic based on byte patterns in the absence of BOM.
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
namespace KlerksSoft
{
public static class TextFileEncodingDetector
{
/*
public static void HttpUploadFile(string url, string file, string paramName, string contentType, NameValueCollection nvc) {
log.Debug(string.Format("Uploading {0} to {1}", file, url));
string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x");
byte[] boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
wr.ContentType = "multipart/form-data; boundary=" + boundary;
wr.Method = "POST";
wr.KeepAlive = true;
wr.Credentials = System.Net.CredentialCache.DefaultCredentials;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace SDKSample
{
public partial class FormatConvertedBitmapExample : Page
{
@draco1023
draco1023 / BrowserTabView.cs
Last active September 15, 2017 02:16
workaround to input chinese char in cef on windows 8.1 and 10
// Copyright © 2010-2015 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System.Windows.Controls;
using System.Windows.Input;
using CefSharp.Example;
using CefSharp.Wpf.Example.Handlers;
namespace CefSharp.Wpf.Example.Views
@draco1023
draco1023 / AsyncHelper.cs
Last active September 15, 2017 02:16
Run async task sync
public static class AsyncHelper
{
/// <summary>
/// Execute's an async Task<T> method which has a void return value synchronously
/// </summary>
/// <param name="task">Task<T> method to execute</param>
public static void RunSync(Func<Task> task)
{
var oldContext = SynchronizationContext.Current;
var synch = new ExclusiveSynchronizationContext();
@draco1023
draco1023 / WordReplace.cs
Created June 27, 2016 12:24
Word replace with netoffice
public void Test() {
NetOffice.WordApi.Application app = null;
NetOffice.WordApi.Document doc = null;
try
{
var tempFile = new FileInfo(path).CopyTo(Path.GetTempFileName(), true);
app = new NetOffice.WordApi.Application();
app.Visible = false;
app.DisplayAlerts = WdAlertLevel.wdAlertsNone;
@draco1023
draco1023 / main.css
Last active September 15, 2017 02:16
Remove Gray Highlight When Tapping Links in Mobile Safari
* { -webkit-tap-highlight-color: rgba(0,0,0,0); }
@draco1023
draco1023 / index.css
Created June 30, 2016 01:50
Chinese font in css from AirBnb
body {
font-family: "Hiragino Sans GB","华文细黑","STHeiti","微软雅黑","Microsoft YaHei",SimHei,"Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 14px;
}