Skip to content

Instantly share code, notes, and snippets.

@njmube
njmube / gist:48ec9e19d2298eab81a41370491d2a5b
Created December 1, 2017 23:21 — forked from naaman/gist:1053217
Hot Swapping With Maven, Jetty and IntelliJ

Hot Swapping With Maven, Jetty and IntelliJ

Based on Configuring Jetty, Maven, and Eclipse together with Hot Swap

I've always been a bit jealous when it comes to the Play! framework and the great dev mode they have for hot swapping classes at runtime. Jetty has a configuration setting, scanIntervalSeconds, that mimics this when working with a more traditional WAR, but does so by looking for changes to a file and restarting the server.

Fortunately, Jetty also provides the ability to rapidly test code with hot swapping. No more server restarts. The trick to getting hot swapping to work is to attach a remote debugger to your Jetty process. The following instructions outline how to do this in IntelliJ (tested with IDEA 10.5 CE).

Modify your jetty-maven-plugin to ignore the scan interval

  1. Open your pom and locate the plugins section
@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
@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 <fyzlman@gmail.com>
* Licensed under The MIT License
* http://www.opensource.org/licenses/mit-license
*/
using System;
@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 / 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 / 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",
class ContactInformationAuctionMessageBuilder : IMailMessageBuilder<ContactInformationAuction>
{
private MailMessage mailMessage;
private StringBuilder body = new StringBuilder();
public ContactInformationAuctionMessageBuilder()
{
mailMessage = new MailMessage();
}
@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>
@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
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;