This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('hello snippet') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace StackExchange.Redis | |
{ | |
static class RedisKeyspaceNotifications | |
{ | |
/// <summary> | |
/// NOTE: For this sample to work, you need to go to the Azure Portal and configure keyspace notifications with "Kxge$" to | |
/// 1) turn on expiration notifications (x), | |
/// 2) general command notices (g) and |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ContextCacheService : ICacheService | |
{ | |
public T GetData<T>(string key) | |
{ | |
try | |
{ | |
var value = HttpContext.Current.Cache[key]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ICacheService | |
{ | |
T GetData<T>(string key); | |
Task<T> GetDataAsync<T>(string key); | |
Task SetDataAsync<T>(string key, T data); | |
bool ClearData(string key); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
builder.Register(c => | |
{ | |
var cacheType = ConfigurationManager.AppSettings["Cache.Type"]; | |
var configCache = (CacheType)Enum.Parse(typeof(CacheType), cacheType); | |
switch (configCache) | |
{ | |
case CacheType.Context: | |
default: | |
return (ICacheService) c.Resolve<ContextCacheService>(); | |
case CacheType.Redis: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validation(id) { | |
id = String(id).trim(); | |
if (id.length > 9 || isNaN(id)) return false; | |
id = id.length < 9 ? ("00000000" + id).slice(-9) : id; | |
return Array.from(id, Number).reduce((counter, digit, i) => { | |
const step = digit * ((i % 2) + 1); | |
return counter + (step > 9 ? step - 9 : step); | |
}) % 10 === 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//this service for catching all error in place | |
import { Injectable, ErrorHandler } from '@angular/core'; | |
import { LogService } from './log.service'; | |
@Injectable() | |
export class ErrorHandlerService extends ErrorHandler { | |
constructor(private logService: LogService) { | |
super(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const a = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static async Task SendEvent(DeviceClient deviceClient) | |
{ | |
var dataBuffer = JsonConvert.SerializeObject( | |
new | |
{ | |
Wind = 10, | |
Humidity = 70, | |
Precipitation = 0 | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
string deviceId = "YOUR-DEVICE-ID".ToLower(); | |
string deviceKey = "YOUR-DEVICE PK OR SK"; | |
string hostname = $"YOUR-ENDPOINT-NAMESPACE.azure-devices.net"; | |
string endpoint = $"{hostname}/devices/{deviceId}"; | |
var token = GenerateSasToken(endpoint, deviceKey); | |
var conn = $"HostName={hostname};CredentialType=SharedAccessSignature;DeviceId={deviceId};SharedAccessSignature={token}"; | |
var deviceClient = DeviceClient.CreateFromConnectionString(conn, TransportType.Amqp_WebSocket_Only); | |
SendEvent(deviceClient).ConfigureAwait(false).GetAwaiter().GetResult(); |
NewerOlder