Skip to content

Instantly share code, notes, and snippets.

View jimmymain's full-sized avatar

Jim jimmymain

  • Palantir (Pty) Ltd
View GitHub Profile
@jimmymain
jimmymain / assembly
Last active August 29, 2015 14:06
references
var name = "itextsharp";
var dir = @"D:\Projects\Online\Service\Enhancements\Release\";
var recurse = true;
var ns = new XmlNamespaceManager(new NameTable());
ns.AddNamespace("x", "http://schemas.microsoft.com/developer/msbuild/2003");
foreach (var file in Directory.EnumerateFiles(dir, "*.csproj", recurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
{
@jimmymain
jimmymain / gist:4ab7dfae1af17d481322
Created December 1, 2014 06:00
summernote sync
$('.row').summernote({
height: 150,
focus: true,
toolbar: [
['style', ['bold', 'italic', 'underline']],
['para', ['ul', 'ol']],
],
onkeyup: function (e) {
$('.active_textarea').val($(this).code());
$('.active_textarea').change();
@jimmymain
jimmymain / ramda
Created June 4, 2015 12:13
ramda
http://jsfiddle.net/CrossEye/Gk6uu/light/
(function(R) {
var incomplete = R.filter(R.where({complete: false}));
var sortByDate = R.sortBy(R.prop('dueDate'));
var sortByDateDescend = R.compose(R.reverse, sortByDate);
var importantFields = R.project(['title', 'dueDate']);
var groupByUser = R.partition(R.prop('username'));
var activeByUser = R.compose(groupByUser, incomplete);
var gloss = R.compose(importantFields, R.take(5), sortByDateDescend);
public static class Extensions
{
public static Task<T> Catch<T,TError> (this Task<T> task, Func<TError,T> onError) where TError : Exception
{
var tcs = new TaskCompletionSource<T> ();
task.ContinueWith (ant =>
{
if (task.IsFaulted && task.Exception.InnerException is TError)
tcs.SetResult (onError ((TError) task.Exception.InnerException));
@jimmymain
jimmymain / waituntilfault.cs
Created November 19, 2015 09:05
wait fault
public static void WaitUnlessFault( Task[] tasks, CancellationToken token )
{
var cts = CancellationTokenSource.CreateLinkedTokenSource(token);
foreach ( var task in tasks ) {
task.ContinueWith(t =>
{
if ( t.IsFaulted ) cts.Cancel();
},
cts.Token,
@jimmymain
jimmymain / AsyncHelpers.cs
Created February 5, 2016 05:51
execute an async / await method synchronously
// https://social.msdn.microsoft.com/Forums/en-US/163ef755-ff7b-4ea5-b226-bbe8ef5f4796/is-there-a-pattern-for-calling-an-async-method-synchronously?forum=async
public static class AsyncHelpers
{
/// <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;
@jimmymain
jimmymain / convertExcel2Sheets
Created July 22, 2016 10:15 — forked from azadisaryev/convertExcel2Sheets
Google Apps Script for converting Excel (.xls or .xlsx) file to Google Spreadsheet. Drive API must be enabled in your script's Advanced Google Services and in Developers Console for the script to work (see https://developers.google.com/apps-script/guides/services/advanced#enabling_advanced_services for details).
/**
* Convert Excel file to Sheets
* @param {Blob} excelFile The Excel file blob data; Required
* @param {String} filename File name on uploading drive; Required
* @param {Array} arrParents Array of folder ids to put converted file in; Optional, will default to Drive root folder
* @return {Spreadsheet} Converted Google Spreadsheet instance
**/
function convertExcel2Sheets(excelFile, filename, arrParents) {
var parents = arrParents || []; // check if optional arrParents argument was provided, default to empty array if not
@jimmymain
jimmymain / Test Async
Created November 2, 2016 08:30 — forked from HEskandari/Test Async
NSubstitute and Async
using System.Threading.Tasks;
using NSubstitute;
using NUnit.Framework;
namespace ClassLibrary1
{
public interface ICalculationServiceAsync
{
Task Calculate();
}
<UserSettings><ApplicationIdentity version="15.0"/><ToolsOptions><ToolsOptionsCategory name="Environment" RegisteredName="Environment"/></ToolsOptions><Category name="Environment_Group" RegisteredName="Environment_Group"><Category name="Environment_FontsAndColors" Category="{1EDA5DD4-927A-43a7-810E-7FD247D0DA1D}" Package="{DA9FB551-C724-11d0-AE1F-00A0C90FFFC3}" RegisteredName="Environment_FontsAndColors" PackageName="Visual Studio Environment Package"><PropertyValue name="Version">2</PropertyValue><FontsAndColors Version="2.0"><Theme Id="{1DED0138-47CE-435E-84EF-9EC1F439B749}"/><Categories><Category GUID="{E0187991-B458-4F7E-8CA9-42C9A573B56C}" FontName="Consolas" FontSize="8" CharSet="1" FontIsDefault="No"><Items><Item Name="SQL String" Foreground="0x00C2FEBA" Background="0x02000000" BoldFont="No"/><Item Name="Comment" Foreground="0x004AA657" Background="0x001E1E1E" BoldFont="No"/><Item Name="Keyword" Foreground="0x00D9A462" Background="0x02000000" BoldFont="No"/></Items></Category><Category GUID="{58E96763-
@jimmymain
jimmymain / HomeController.cs
Created July 17, 2017 08:44 — forked from ahmad-moussawi/HomeController.cs
A view Render for Razor (aspnetcore RC2)
public class HomeController : Controller {
private readonly ViewRender view;
public HomeController (ViewRender view) {
this.view = view
}
public string Test () {
// render ~/Views/Emails/ResetCode