Skip to content

Instantly share code, notes, and snippets.

View MahdiKarimipour's full-sized avatar
🎯
Focusing

MK MahdiKarimipour

🎯
Focusing
  • TechnologyLeads
  • Sydney, Australia
View GitHub Profile
@MahdiKarimipour
MahdiKarimipour / pellerex-realtime-messaging-send-message.js
Created December 23, 2021 07:01
Pellerex Realtime Messaging Send Message Method
sendMessage = async (message) => {
let fromUserId = this.props.user.userId;
let toUserIds = this.props.parties?.filter(p => p !== fromUserId);
let chatGroupId = isEmpty(this.props.chatGroupId) ? this.state.chatGroupId : this.props.chatGroupId;
const data = {
message: message,
context: this.props.context,
chatGroupId: chatGroupId,
fromUserId: fromUserId,
@MahdiKarimipour
MahdiKarimipour / pellerex-realtime-messaging-connect-to-hub.js
Created December 23, 2021 06:50
Pellerex Realtime Messaging Connect to Hub
initiateChatRoomSetup = async () => {
const connection = new HubConnectionBuilder()
.withUrl(
`${'backend-api/hubs/chat'}`,
{
accessTokenFactory: () => this.props.accessToken,
UseDefaultCredentials: true
}
)
.configureLogging(LogLevel.Trace)
@MahdiKarimipour
MahdiKarimipour / pellerex-realtime-messaging-signalr-hub-config.cs
Created December 23, 2021 06:40
Pellerex Realtime Messaging SignalR Hub Config
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<ChatHub>("/hubs/chat");
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
@MahdiKarimipour
MahdiKarimipour / pellerex-realtime-messaging-chat-component.js
Created December 23, 2021 06:33
Pellerex Realtime Messaging Chat Function
<Chat
parties={this.state.chatParticipantIds}
context={General.ChatContext.DirectMessages}
chatGroupId={this.state.chatGroupId}
/>
@MahdiKarimipour
MahdiKarimipour / pellerex-realtime-messaging-hub.cs
Created December 23, 2021 05:58
Pellerex Realtime Messaging with SignalR Hubs
[Authorize]
public class ChatHub : Hub
{
private readonly IChatService chatService;
public ChatHub(IChatService chatService)
{
this.chatService = chatService;
}
@MahdiKarimipour
MahdiKarimipour / pellerex-calling-ai-apis.cs
Last active March 18, 2023 12:14
Pellerex Calling AI APIs
curl --location 'https://api.pellerex.com/proxy/35af8351-......7cf77c6a9615/v1/hello' \
--header 'Authorization: Bearer eyJhbGciOiJo......ru3_I1YIPCCYw5wCF9ty2nhF4_XD9S0' \
--header 'Content-Type: application/json' \
--data-raw '{
"context": "Jim is walking through the woods.",
"question": "Where is he walking?"
}'
curl --location --request POST 'https://api.pellerex.com/identity/v2/account/login' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic amFtZX.....jMTIz' \
--data-raw '{}'
@MahdiKarimipour
MahdiKarimipour / pellerex-calling-identity-api-refresh-token.cs
Last active November 21, 2021 07:10
Call Pellerex Login Endpoint: Refresh Token
curl --location --request POST 'https://api.pellerex.com/identity/v1/account/refresh-token' \
--header 'Content-Type: application/json' \
--data-raw '{
"AccessToken": "eyJhbGciOiJodHRw....C7HuVE-wWsxQ",
"RefreshToken": "CfDJ8MNEJ5U....pjjlcYcmn4uLQIxwukFQ=="
}'
@MahdiKarimipour
MahdiKarimipour / performance-improvement-response-caching-endpoint-level.cs
Last active October 29, 2021 00:41
Asp.NET Response Caching at the End Point Level
[HttpGet("product")]
[MapToApiVersion("1")]
[ResponseCache(VaryByQueryKeys = new[] { "field", "category" }, Duration = 10 * 60)]
public async Task<ActionResult<IEnumerable<ProductViewModel>>> GetProducts(
[FromQuery] string field,
[FromQuery] string category)
{
return Ok(response);
}
@MahdiKarimipour
MahdiKarimipour / performance-improvment-react-caching-and-compression.cs
Created October 29, 2021 00:04
Caching and Compression in Asp.NET for React
public void ConfigureServices(IServiceCollection services)
{
services.AddResponseCompression(options =>
{
options.Providers.Add<BrotliCompressionProvider>();
options.Providers.Add<GzipCompressionProvider>();
});
services.AddResponseCaching();
}