Skip to content

Instantly share code, notes, and snippets.

private string GetManufacturer(string MacAddress)
{
using (ISession session = Global._DatabaseConn.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
string strManuFacturer = "N/A";
var OID = session.Query<normutils.data.Entities.MACIdentifier>();
var Type = (from t in OID
where t.ID == MacAddress.Substring(0,8)
private void UpdateProducts() {
using (var context = new MyEntities()) {
using (var cn = context.Database.Connection) {
cn.Open();
using (var tr = context.Database.Connection.BeginTransaction()) {
try {
//1. ADO.NETで独自のSQL文を実行。
var sql = "UPDATE [Products] SET [Price] = [Price] * 1.1 ";
var cmd = cn.CreateCommand();
cmd.Transaction = tr;
@njmube
njmube / add-to-cart.php
Last active August 29, 2015 14:26 — forked from webaware/add-to-cart.php
WooCommerce purchase page add-to-cart with quantity and AJAX, by customising the add-to-cart template in the WooCommerce loop. See blog post for details: http://snippets.webaware.com.au/snippets/woocommerce-add-to-cart-with-quantity-and-ajax/
<?php
/**
* Loop Add to Cart -- with quantity and AJAX
* requires associated JavaScript file qty-add-to-cart.js
*
* @ref: http://snippets.webaware.com.au/snippets/woocommerce-add-to-cart-with-quantity-and-ajax/
* @ref: https://gist.github.com/mikejolley/2793710/
*/
// add this file to folder "woocommerce/loop" inside theme
@njmube
njmube / SmtpClientExtensions.cs
Created December 1, 2015 05:33 — forked from mattbenic/SmtpClientExtensions.cs
Extension method to have SmtpClient's SendMailAsync respond to a CancellationToken
using System;
using System.Net.Mail;
using System.Threading;
using System.Threading.Tasks;
public static class SmtpClientExtensions
{
/// <summary>
/// Extension method to have SmtpClient's SendMailAsync respond to a CancellationToken
/// </summary>
class ContactInformationAuctionMessageBuilder : IMailMessageBuilder<ContactInformationAuction>
{
private MailMessage mailMessage;
private StringBuilder body = new StringBuilder();
public ContactInformationAuctionMessageBuilder()
{
mailMessage = new MailMessage();
}
@njmube
njmube / MailBuilderTest.cs
Created December 1, 2015 05:37 — forked from ferclaverino/MailBuilderTest.cs
Liskov - step 0
[TestFixture]
class MailBuilderTest
{
[Test]
public void TestContactInformation()
{
// arrange
ContactInformation contactInformation = new ContactInformation()
{
FirstName = "Homero",
@njmube
njmube / sendemailsasync.cs
Created December 5, 2015 04:51
Sending multiple emails in parallel using SmtpClient.SendMailAsync with async and Task.WhenAll
var sendEmailTasks = recipientList.Select(async recipient =>
{
var message = new MailMessage { To = { recipient }, ... };
// instantiate a new client for each mail because of this:
// http://www.codefrenzy.net/2012/01/30/how-asynchronous-is-smtpclient-sendasync/
using (var smtpClient = new SmtpClient())
{
await smtpClient.SendMailAsync(message);
}
@njmube
njmube / ButtonStackPanel.xaml
Created December 7, 2015 23:30 — forked from markheath/ButtonStackPanel.xaml
Example WPF Button Template
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<Style x:Key="MyFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Control}">
<Grid Margin="3 2">
@njmube
njmube / Age.cs
Created January 5, 2016 17:15 — forked from faisalman/Age.cs
Calculate Age (Years + Months + Days) in C#
/**
* Calculate Age in C#
* https://gist.github.com/faisalman
*
* Copyright 2012-2013, Faisalman <[email protected]>
* Licensed under The MIT License
* http://www.opensource.org/licenses/mit-license
*/
using System;
@njmube
njmube / TRESTClient_ CreateAnonymousThread.pas
Created April 22, 2017 19:49
TRESTClient CreateAnonymousThread Delphi
uses IPPeerClient,REST.Client, Data.Bind.Components, Data.Bind.ObjectScope;
procedure TForm1.Button1Click(Sender: TObject);
var
rc: TRESTClient;
rr: TRESTRequest;
res: TRESTResponse;
begin
TThread.CreateAnonymousThread(
procedure
begin