Skip to content

Instantly share code, notes, and snippets.

@shamohai
shamohai / woocommerce-csharp-client
Created July 2, 2016 11:57 — forked from jakobt/woocommerce-csharp-client
Consuming WooCommerce REST API from C#
//C# port of the https://github.com/kloon/WooCommerce-REST-API-Client-Library
//Including handling of woocommerce insisting on uppercase UrlEncoded entities
public class WoocommerceApiClient
{
private static byte[] HashHMAC(byte[] key, byte[] message)
{
var hash = new HMACSHA256(key);
return hash.ComputeHash(message);
}
@shamohai
shamohai / Default.aspx
Created July 2, 2016 16:30 — forked from cmcdonaldca/Default.aspx
Using Rob Conery's C# Shopify API Wrapper
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ListView ID="Products" ItemPlaceholderID="items" runat="server">
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="items" runat="server"></asp:PlaceHolder>
@shamohai
shamohai / gist:0b7f413ec26e718278ce44ecd0010538
Created July 3, 2016 15:28 — forked from henryyan/gist:5c3aa37f5e9d4fa217ca
auto resize jqgrid width and height
/**
* 改变窗口大小的时候自动根据iframe大小设置jqGrid列表宽度和高度
* 参数说明:{
* enableAutoResize : 是否开启自动高度和宽度调整开关
* dataGrid : jqGrid数据列表的ID
* callback : 计算完dataGrid需要的高度和宽度后的回调函数
* width : 默认为iframe的宽度,如果指定则设置为指定的宽度
* height : 默认为iframe的高度,如果指定则设置为指定的高度
* beforeAutoResize : 窗口大小调整时自动设置之前
* afterAutoResize : 窗口大小调整时自动设置之后
public class ApiLogEntry
{
public long ApiLogEntryId { get; set; } // The (database) ID for the API log entry.
public string Application { get; set; } // The application that made the request.
public string User { get; set; } // The user that made the request.
public string Machine { get; set; } // The machine that made the request.
public string RequestIpAddress { get; set; } // The IP address that made the request.
public string RequestContentType { get; set; } // The request content type.
public string RequestContentBody { get; set; } // The request content body.
public string RequestUri { get; set; } // The request URI.
public class ApiLogHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var apiLogEntry = CreateApiLogEntryWithRequestData(request);
if (request.Content != null)
{
await request.Content.ReadAsStringAsync()
.ContinueWith(task =>
{
protected void Application_Start()
{
GlobalConfiguration.Configuration.MessageHandlers.Add(new ApiLogHandler());
}
@shamohai
shamohai / gist:b30f064f4e0c1dd79eb81880cf93555f
Created March 12, 2017 06:07 — forked from metavida/gist:601058
How to test OAuth with the Haiku LMS API, using C#.
// Based on code from the following sources:
// * http://www.voiceoftech.com/swhitley/index.php/2009/03/twitter-oauth-with-net/
// * http://oauth.googlecode.com/svn/code/csharp/
// Note: if you're using mono the following command will compile this code `gmcs -r:System.Web.dll this_file.cs`
using System;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Text;
using System.Net;
@shamohai
shamohai / OtpAuthenticator.cs
Created May 7, 2017 11:36 — forked from BravoTango86/OtpAuthenticator.cs
C# OTP Implementation with TOTP and HOTP
/*
* Copyright (C) 2016 BravoTango86
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@shamohai
shamohai / js-crypto-libraries.md
Created June 11, 2019 01:15 — forked from jo/js-crypto-libraries.md
List of JavaScript Crypto libraries.

JavaScript Crypto Libraries

I start with a list and plan to create a comparison table.

WebCryptoAPI

http://www.w3.org/TR/WebCryptoAPI/

This specification describes a JavaScript API for performing basic cryptographic operations in web applications, such as hashing, signature generation and verification, and encryption and decryption. Additionally, it describes an API for applications to generate and/or manage the keying material necessary to perform these operations. Uses for this API range from user or service authentication, document or code signing, and the confidentiality and integrity of communications.

@shamohai
shamohai / AESGCM.cs
Created June 16, 2019 16:25 — forked from jbtule/AESGCM.cs
I have two code examples that I wrote for best practices encrypting a string in c#. They are both using authenticated encryption. http://stackoverflow.com/a/10366194/637783
/*
* This work (Modern Encryption of a String C#, by James Tuley),
* identified by James Tuley, is free of known copyright restrictions.
* https://gist.github.com/4336842
* http://creativecommons.org/publicdomain/mark/1.0/
*/
using System;
using System.IO;
using System.Text;