Skip to content

Instantly share code, notes, and snippets.

@theRealNG
theRealNG / shopping_cart_test.rb
Created February 1, 2024 01:02
Shopping Cart Test case using MiniTests
class ShoppingCartTest < MiniTest::Test
def setup
@cart = ShoppingCart.new
end
def test_calculates_total_price_with_taxes
item = Item.new("Apple", 10.00)
# Stubbing the add_item method
@cart.stub(:add_item, nil) do
@theRealNG
theRealNG / shopping_cart_spec.rb
Last active February 7, 2024 00:31
Shopping Cart test cases using RSpec
require "rspec"
describe "ShoppingCart" do
before { @cart = ShoppingCart.new }
describe "#total_price_with_taxes" do
it "calculates the total price with taxes" do
# Mocking external calls
allow(TaxCalculator).to receive(:calculate_tax).and_return(1.50)
@theRealNG
theRealNG / LengthBasedExampleSelector.py
Created January 15, 2024 06:30
Example using Length based example selector
from langchain.prompts.example_selector import LengthBasedExampleSelector
example_selector = LengthBasedExampleSelector(
examples=examples,
example_prompt=example_prompt,
max_length=50 # this sets the max length that examples should be
)
dynamic_prompt_template = FewShotPromptTemplate(
example_selector=example_selector, # use example_selector instead of examples
@theRealNG
theRealNG / FewShots example.py
Created January 15, 2024 06:26
Few Shots example
from langchain import FewShotPromptTemplate
# create our examples
examples = [
{
"query": "How are you?",
"answer": "I can't complain but sometimes I still do."
}, {
"query": "What time is it?",
"answer": "It's time to get a watch."
@theRealNG
theRealNG / app.py
Last active July 5, 2023 07:07
Flask & Redis python
import time
import redis
from flask import Flask
app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)
def get_hit_count():
retries = 5
@theRealNG
theRealNG / app.py
Created July 5, 2023 06:42
Hello World Flask
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == "__main__":
app.run()

Keybase proof

I hereby claim:

  • I am therealng on github.
  • I am therealng (https://keybase.io/therealng) on keybase.
  • I have a public key ASAnKV36G5jO3sGHecTY6zd8LCyrYxKc_3TbFgEmSfdGqwo

To claim this, I am signing this object:

@theRealNG
theRealNG / 0_reuse_code.js
Created October 12, 2015 04:32
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@theRealNG
theRealNG / using active_model_serialization
Last active August 29, 2015 14:20
User using as_json vs active_model_serialization
def show
respond_with User.find(params[:id])
end
def create
user = User.new(user_params)
if user.save
render json: user, status: :created, location: [:api, user]
else
render json: { errors: user.errors }, status: :unprocessable_entity
@theRealNG
theRealNG / gist:ab4652bda1109517fa6f
Created April 28, 2015 05:22
Over ridding devise current_user to use for the API authentication
def current_user
@current_user ||= User.find_by(auth_token: request.headers["Authorization"])
end