Skip to content

Instantly share code, notes, and snippets.

View gtechsltn's full-sized avatar
🍊

Nguyen Viet Manh gtechsltn

🍊
View GitHub Profile
@gtechsltn
gtechsltn / gist:7f783b614e9b31e7e19c11e2121d4606
Created April 16, 2024 09:38 — forked from alex-groshev/gist:1e047950cb9b2d12c212
Invoking multiple handlers periodically from Topshelf Windows Service (using System.Threading.Timer)
using System;
using System.Collections.Generic;
using System.Threading;
using Topshelf;
namespace ConsoleApplication
{
public interface IProcess
{
void Perform();
using System;
using System.Threading;
class Program
{
static void Main()
{
AutoResetEvent reset = new AutoResetEvent(false);
StatusChecker status = new StatusChecker(5);
@gtechsltn
gtechsltn / Service1.cs
Last active April 16, 2024 09:36 — forked from niisar/Service1.cs
Windows Service using System.Threading.Timer
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Configuration;
using System.IO;
@gtechsltn
gtechsltn / IDbConnectionExtensions.cs
Created April 5, 2024 06:49 — forked from gbachs/IDbConnectionExtensions.cs
Extension methods for IDbConnection
public static class IDbConnectionExtensions
{
public static IDbCommand CreateTextCommand(this IDbConnection thisObj, string sql)
{
return CreateCommand(thisObj, sql, CommandType.Text);
}
public static IDbCommand CreateStoredProcedureCommand(this IDbConnection thisObj, string storedProcedure)
{
return CreateCommand(thisObj, storedProcedure, CommandType.StoredProcedure);
@gtechsltn
gtechsltn / GenerateOpenApiOnBuildFromNet8MinimalApi.md
Created March 30, 2024 17:49 — forked from VincentH-Net/GenerateOpenApiOnBuildFromNet8MinimalApi.md
Generate OpenApi.json on build from ASP.NET 8 Minimal API

To generate OpenApi.json on build from an ASP.NET 8 Minimal API, follow these steps:

  1. In Visual Studio for Windows 17.7.0 or later, create a new ASP.NET Core API project

  2. Follow these instructions to install Swashbuckle.AspNetCore.Cli as a local dotnet tool in your project

  3. Add these NuGet packages (or later versions) to the project:

  <ItemGroup>
  	<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0-preview.4.23260.4" />
@gtechsltn
gtechsltn / SolrQuerySyntaxPrimer.md
Created March 19, 2024 07:52 — forked from mankyKitty/SolrQuerySyntaxPrimer.md
The documentation around the basics of the Solr query syntax is terrible, this is an attempt to alleviate the doc-shock associated with trying to learn some fundamentals.

Solr Query Syntax Basics

This is a super basic beginners guide to Solr Lucene query syntax. We're going to cover running a straightforward query, as well as some of the more useful functionality such as filtering and creating facets. We'll point out some things you can't do and generally give you enough instruction so that you can get yourself into trouble.

For testing you need a REST client capable of sending requests to your Solr instance. Either RESTClient for Firefox or Postman for Chrome are good choices.

Misc

Request Specific Fields

To specify a list of fields to return instead of the default Solr response use fl and provide a comma delimited list of fields:

@gtechsltn
gtechsltn / ajaxfileupload.js
Created March 14, 2024 14:19 — forked from HenrikJoreteg/ajaxfileupload.js
AJAX file uploading using jQuery and XMLHttpRequest 2.0 and adding listener for progress updates
// grab your file object from a file input
$('#fileInput').change(function () {
sendFile(this.files[0]);
});
// can also be from a drag-from-desktop drop
$('dropZone')[0].ondrop = function (e) {
e.preventDefault();
sendFile(e.dataTransfer.files[0]);
};
@gtechsltn
gtechsltn / sha256.js
Created March 12, 2024 07:22 — forked from GaspardP/sha256.js
SHA-256 with Javascript and Web Crypto
// Computes the SHA-256 digest of a string with Web Crypto
// Source: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
function sha256(str) {
// Get the string as arraybuffer.
var buffer = new TextEncoder("utf-8").encode(str)
return crypto.subtle.digest("SHA-256", buffer).then(function(hash) {
return hex(hash)
})
}
@gtechsltn
gtechsltn / pyclean.sh
Created January 29, 2024 04:34 — forked from technocake/pyclean.sh
Clear all python cache in directory
# pyclean command to clear all python cache in a directory
# source: https://stackoverflow.com/questions/28991015/python3-project-remove-pycache-folders-and-pyc-files
# in .bash_profile / .bash_rc etc put:
pyclean () {
find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete
}
@gtechsltn
gtechsltn / emberjs-cheat-sheet.md
Created January 24, 2024 02:17 — forked from ezy/emberjs-cheat-sheet.md
Ember.js Cheat Sheet

Core concepts

Model

  • An object that stores data (data persistance layer abstraction).
  • Templates transforms models into HTML.
  • Same thing as Rails model.

Template