Skip to content

Instantly share code, notes, and snippets.

console.log('hello snippet')
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
public class ContextCacheService : ICacheService
{
public T GetData<T>(string key)
{
try
{
var value = HttpContext.Current.Cache[key];
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);
}
@avisiboni
avisiboni / module.cs
Created November 30, 2020 14:48
cache resolver
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:
@avisiboni
avisiboni / id_number_validtion.js
Created November 29, 2020 15:53
Israel id number validation
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 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();
}
const a = 1
@avisiboni
avisiboni / SendEvent
Created December 23, 2019 09:44
Send event from device function
static async Task SendEvent(DeviceClient deviceClient)
{
var dataBuffer = JsonConvert.SerializeObject(
new
{
Wind = 10,
Humidity = 70,
Precipitation = 0
});
@avisiboni
avisiboni / Main
Created December 23, 2019 09:43
Main function
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();