Skip to content

Instantly share code, notes, and snippets.

package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class BookController {
package com.example.demo;
import lombok.Getter;
import lombok.Setter;
public class Book {
@Getter
@Setter
private String id;
package common;
import java.util.Random;
public class MyRandom {
private String alphabets = "abcdefghijklmnopqrstuvwxyz";
private String numbers = "0123456789";
private String alphanumerics = numbers + alphabets;
public String randomizer(String validChars, int length){
@oofnivek
oofnivek / luhn.rb
Last active August 23, 2022 14:25
Luhn algorithm
def random(n)
s = ''
for i in 0..n-1
s += rand(0..9).to_s
end
return s
end
def get_digit(s, i)
output = 0
@oofnivek
oofnivek / color.rb
Created August 23, 2022 12:13
Ruby colorize terminal text module
require 'colorize'
puts 'black'.black
puts 'light_black'.light_black
puts 'red'.red
puts 'light_red'.light_red
puts 'green'.green
puts 'light_green'.light_green
puts 'yellow'.yellow
puts 'light_yellow'.light_yellow
package main
import(
"fmt"
"reflect"
)
type Cat struct{}
func (c Cat) Say() string{return "meow"}
package main
import (
"fmt"
)
type Cat struct{}
func (c Cat) Say() string { return "meow" }
type Dog struct{}
@oofnivek
oofnivek / monty.rb
Last active November 19, 2021 03:03
Monty Hall probability
def monty(switch_choice)
doors = ['1','2','3'] #can be renamed to A,B,C
prize = doors[rand(doors.length)]
choose1 = doors[rand(doors.length)]
open = prize #to force it into while loop
while open==prize or open==choose1
open = doors[rand(doors.length)]
end
puts 'prize = door %s' % prize
puts 'choose1 = door %s' % choose1
@oofnivek
oofnivek / vue_table.htm
Created September 17, 2021 04:50
Populate table rows dynamically using Vue.js from JSON array
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
</head>
<body>
<table border="1">
<thead>
<tr>
<th>Fruit</th>
<th>Quantity</th>
require 'mysql2'
def my_db
return Mysql2::Client.new(
:host => '127.0.0.1',
:username => 'root',
:password => 'password',
:encoding => 'utf8mb4',
:database => 'medium_story',
:ssl_mode => 'disabled',