Skip to content

Instantly share code, notes, and snippets.

View Kshitij-Dhakal's full-sized avatar

Kshitij Dhakal Kshitij-Dhakal

View GitHub Profile
@Kshitij-Dhakal
Kshitij-Dhakal / default.conf
Created July 19, 2023 09:22
Dynamic route in nginx config
location ~ ^/v1/blog/(?<blogId>[^/]+) {
# Access the dynamic blogId value using the $blogId variable
proxy_pass http://blog_server;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
}
@Kshitij-Dhakal
Kshitij-Dhakal / Result.java
Created July 19, 2023 08:22
Rust Result Emulation
public class Result<T, E> {
T t;
E e;
private Result() {
}
public static <T, E> Result<T, E> ok(T ok) {
var teResult = new Result<T, E>();
teResult.t = ok;
@Kshitij-Dhakal
Kshitij-Dhakal / FieldMaskExample.java
Last active November 8, 2022 05:28
Field Mask Demo
package org.example;
import com.google.protobuf.FieldMask;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.FieldMaskUtil;
import com.google.protobuf.util.JsonFormat;
import org.example.pb.Address;
import org.example.pb.UpdateUserRequest;
import org.example.pb.User;
import org.slf4j.Logger;
package com.example.demo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import javax.jms.JMSException;
// Reference https://unicode.org/emoji/charts/full-emoji-list.html
1 U+1F600 😀 grinning face face | grin | grinning face
2 U+1F603 😃 grinning face with big eyes face | grinning face with big eyes | mouth | open | smile
3 U+1F604 😄 grinning face with smiling eyes eye | face | grinning face with smiling eyes | mouth | open | smile
4 U+1F601 😁 beaming face with smiling eyes beaming face with smiling eyes | eye | face | grin | smile
5 U+1F606 😆 grinning squinting face face | grinning squinting face | laugh | mouth | satisfied | smile
6 U+1F605 😅 grinning face with sweat cold | face | grinning face with sweat | open | smile | sweat
7 U+1F923 🤣 rolling on the floor laughing face | floor | laugh | rofl | rolling | rolling on the floor laughing | rotfl
8 U+1F602 😂 face with tears of joy face | face with tears of joy | joy | laugh | tear
9 U+1F642 🙂 slightly smiling face face | slightly smiling face | smile
@Kshitij-Dhakal
Kshitij-Dhakal / with_probability_of_success.dart
Last active July 19, 2023 08:22
Given the probability of something happening (p), and sample size (n), get a boolean such that, if the method is ran (n) number of times then you are likely to get (p*n) trues.
import 'dart:math';
Random _random = new Random();
int getRandomInt(int limit) => _random.nextInt(limit);
double randomDouble() => _random.nextDouble();
///Given the probability of something happening (p), and sample size (n),
///get a boolean such that, if the method is ran (n) number of times then
include "secure"
av.api.key = "apiKey"
av.api.secret = "apiSecret"
av.base.url = "http://localhost"
mqtt.broker = ""
mqtt.username = ""
mqtt.password = ""
policy.url = ""
service.auth.port = 9010
@Kshitij-Dhakal
Kshitij-Dhakal / InsertOrUpdate.java
Created June 9, 2021 12:20
InsertOrUpdate.java
package com.treeleaf.anydone.conversation.service.repo;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.treeleaf.SqlRepo;
import com.treeleaf.ex.TreeleafException;
import com.treeleaf.sql.JDBCException;
import com.treeleaf.sql.SqlDataSource;
import java.sql.Connection;
@Kshitij-Dhakal
Kshitij-Dhakal / camera_button.dart
Created June 3, 2021 15:56
This is button that shows camera screen when pressed. If you capture image then it will navigate back to original screen and display image just capture instead of button. Image still functions same as button and can be pressed to open camera again. If you already have image in network then you can pass network image to display in place of button.
import 'dart:io';
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
bool isBlank(String? str) => str == null || str.isEmpty;
class OpenCameraButton extends StatelessWidget {
final Function(String imgPath) onCapture;
final String? fileImage;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="preconnect" href="https://fonts.gstatic.com"/>
<link
href="https://fonts.googleapis.com/css2?family=Roboto:wght@100;300;400;500;700;900;display=swap"
rel="stylesheet"