Skip to content

Instantly share code, notes, and snippets.

View skarlekar's full-sized avatar

Srini Karlekar skarlekar

View GitHub Profile
@skarlekar
skarlekar / prompt-compare.py
Created May 18, 2024 21:20
This Python script provides a utility to compute the cosine similarity between two text sentences. This script is useful for applications like plagiarism detection, semantic search, or text data preprocessing where understanding the degree of similarity between texts is crucial.
"""
This Python script provides a utility to compute the cosine similarity between two text sentences using the TF-IDF
(Term Frequency-Inverse Document Frequency) vectorization approach.
Key Components:
1. Import Statements: The script begins by importing necessary modules:
- TfidfVectorizer from sklearn.feature_extraction.text for converting text data into a matrix of TF-IDF features.
- cosine_similarity from sklearn.metrics.pairwise to compute the similarity between two vectors in the TF-IDF space.
- sys for accessing command-line arguments.
@cedrickchee
cedrickchee / llama-7b-m1.md
Last active June 22, 2024 01:26
4 Steps in Running LLaMA-7B on a M1 MacBook with `llama.cpp`

4 Steps in Running LLaMA-7B on a M1 MacBook

The large language models usability

The problem with large language models is that you can’t run these locally on your laptop. Thanks to Georgi Gerganov and his llama.cpp project, it is now possible to run Meta’s LLaMA on a single computer without a dedicated GPU.

Running LLaMA

There are multiple steps involved in running LLaMA locally on a M1 Mac after downloading the model weights.

@thomasaarholt
thomasaarholt / gaussian.py
Last active February 6, 2024 11:19
Fastest found numpy method of generating a 2D gaussian kernel of size n x n and standard deviation std.
import numpy as np
from scipy import signal
def gaussian_kernel(n, std, normalised=False):
'''
Generates a n x n matrix with a centered gaussian
of standard deviation std centered on it. If normalised,
its volume equals 1.'''
gaussian1D = signal.gaussian(n, std)
gaussian2D = np.outer(gaussian1D, gaussian1D)
@tanaikech
tanaikech / submit.md
Last active January 29, 2024 01:17
Uploading Files From Local To Google Drive by Python without Quickstart

Uploading Files From Local To Google Drive by Python without Quickstart

This is a sample script for uploading files from local PC to Google Drive using Python. In this sample, Quickstart is not used. So when you use this script, please retrieve access token.

Curl sample :

curl -X POST \
    -H "Authorization: Bearer ### access token ###" \
    -F "metadata={name : 'sample.png', parents: ['### folder ID ###']};type=application/json;charset=UTF-8" \
    -F "file=@sample.png;type=image/png" \
 "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart"
@hiddentao
hiddentao / RoleBasedAcl.sol
Last active March 10, 2020 03:27
Ethereum solidity contract for role-based access control
pragma solidity ^0.4.10;
contract RoleBasedAcl {
address creator;
mapping(address => mapping(string => bool)) roles;
function RoleBasedAcl () {
creator = msg.sender;
}
@maurelian
maurelian / console.sol
Last active February 25, 2022 18:44
A JS style console.log() function for solidity.
pragma solidity ^0.4.10;
// Update: Just use HardHat's: https://github.com/nomiclabs/hardhat/blob/master/packages/hardhat-core/console.sol
// Enables event logging of the format `console.log('descriptive string', variable)`,
// without having to worry about the variable type (as long as an event has been declared for that type in the
// Console contract.
contract Console {
event LogUint(string, uint);
@alexcasalboni
alexcasalboni / amazon-rekognition.md
Last active September 6, 2023 15:20
Amazon Rekognition - Python Code Samples

Amazon Rekognition - Python Code Samples

  1. Labels Detection
  2. Faces Detection
  3. Faces Comparison
  4. Faces Indexing
  5. Faces Search
@Mindgames
Mindgames / gist:556dc7d1e452d0cefcb7
Created February 11, 2016 22:04
Amazon S3 download with Curl
#!/bin/sh
file=path/to/file
bucket=your-bucket
resource="/${bucket}/${file}"
contentType="application/x-compressed-tar"
dateValue="`date +'%a, %d %b %Y %H:%M:%S %z'`"
stringToSign="GET
${contentType}
${dateValue}
${resource}"
@wosephjeber
wosephjeber / ngrok-installation.md
Last active June 4, 2024 07:48
Installing ngrok on Mac

Installing ngrok on OSX

For Homebrew v2.6.x and below:

brew cask install ngrok

For Homebrew v2.7.x and above:

@manjeshpv
manjeshpv / passport.js
Last active February 29, 2024 15:11
Passport.js using MySQL for Authentication with Express
// config/passport.js
// load all the things we need
var LocalStrategy = require('passport-local').Strategy;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',