Skip to content

Instantly share code, notes, and snippets.

View ddh's full-sized avatar
🔄
Loading...

Arthur (Duy) Huynh ddh

🔄
Loading...
View GitHub Profile
@ddh
ddh / probability.java
Last active November 26, 2019 06:58
Implementing probability in Java
Random random = new Random();
int hit = 0;
int miss = 0;
for (int i = 0; i < 100; i++) {
if (random.nextDouble() <= 0.25) {
hit++;
} else {
miss++;
@ddh
ddh / wagnerfisheralgo
Last active November 26, 2019 06:58
Wagner-Fisher Levenschtein edit distance between two strings.Source: http://www.sanfoundry.com/java-program-wagner-fischer-algorithm/
/** Function to get levenshtein distance between 2 strings **/
public int getLevenshteinDistance(String str1, String str2)
{
int len1 = str1.length();
int len2 = str2.length();
int[][] arr = new int[len1 + 1][len2 + 1];
for (int i = 0; i <= len1; i++)
arr[i][0] = i;
for (int i = 1; i <= len2; i++)
arr[0][i] = i;
@ddh
ddh / lowerToUpperC
Created May 19, 2015 00:25
Algorithm: ASCII value of 'A' is 65 while 'a' is 97. Difference between them is 97 – 65 = 32 So if we will add 32 in the ASCII value of 'A' then it will be 'a' and if will we subtract 32 in ASCII value of 'a' it will be 'A'. It is true for all alphabets. In general rule: Upper case character = Lower case character – 32 Lower case character = Upp…
//Conversion from uppercase to lower case using c program
#include<stdio.h>
#include<string.h>
int main(){
char str[20];
int i;
printf("Enter any string->");
scanf("%s",str);
printf("The string is->%s",str);
@ddh
ddh / waka-box
Created March 12, 2020 02:32
Weekly development breakdown
hi!
@ddh
ddh / System Design.md
Created April 6, 2020 07:14 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@ddh
ddh / check_for_unused_vcr_cassettes.rb
Created June 30, 2022 00:52
Checks with VCR Cassettes were not used during a rspec run
require 'set'
USED_CASSETTES = Set.new
module CassetteReporter
def insert_cassette(name, options = {})
USED_CASSETTES << VCR::Cassette.new(name, options).file
super
end
end
VCR.extend(CassetteReporter)