Skip to content

Instantly share code, notes, and snippets.

@aakashjsr
aakashjsr / lps_array_compute.py
Created August 31, 2021 17:14
LPS Array computation for KMP algorithm
def computeLPSList(pattern):
lps = [0] * len(pattern)
index = 1
_len = 0
while index < len(pattern):
if pattern[index] == pattern[_len]:
_len += 1
lps[index] = _len
@aakashjsr
aakashjsr / counter.html
Created March 12, 2021 18:29
HTML counter
<style>
.container {
display: flex;
align-items: center;
flex-direction: column
}
#counter {
font-size: 70px;
}
def match(template, ptr, char):
if ptr < len(template):
template_char = template[ptr]
if template_char == 'A' and char == 'T':
return True
if template_char == 'T' and char == 'A':
return True
if template_char == 'G' and char == 'C':
return True
if template_char == 'C' and char == 'G':
def match(template, ptr, char):
if ptr < len(template):
template_char = template[ptr]
if template_char == 'A' and char == 'T':
return True
if template_char == 'T' and char == 'A':
return True
if template_char == 'G' and char == 'C':
return True
if template_char == 'C' and char == 'G':
def match(template, ptr, char):
if ptr < len(template):
template_char = template[ptr]
if template_char == 'A' and char == 'T':
return True
if template_char == 'T' and char == 'A':
return True
if template_char == 'G' and char == 'C':
return True
if template_char == 'C' and char == 'G':
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
import csv, psycopg2, re, json
class DataProcessor:
def __init__(self):
self.valid_date = "2019-05-21"
self.file_name = 'log-actions-follow_2019-05-20_08-50PM_subset.csv'
self.data = []
import csv, psycopg2, re, json
class DataProcessor:
def __init__(self):
self.file_name = 'spreadsheet.csv'
self.data = []
self.map = {
"ScrapedDate": "lead_find_date",
"Userid": "user_id",
def insert_data(self):
chunk_size = 1000
query = """
INSERT INTO test_ig_leads (lead_find_date, user_id, username, lead_find_keyword, is_private, follower_count, following_count, media_count) SELECT lead_find_date, user_id, username, lead_find_keyword, is_private, follower_count, following_count, media_count FROM json_populate_recordset(null::test_ig_leads, %s);"""
length = len(self.data)
start = 0
while start <= length:
rowset = self.data[start:start+chunk_size]
cursor = self.conn.cursor()
cursor.execute(query, (json.dumps(rowset), ))
def insert_data(self):
query = """
INSERT INTO test_ig_leads (lead_find_date, user_id, username, lead_find_keyword, is_private, follower_count, following_count, media_count) SELECT lead_find_date, user_id, username, lead_find_keyword, is_private, follower_count, following_count, media_count FROM json_populate_recordset(null::test_ig_leads, %s);"""
cursor = self.conn.cursor()
cursor.execute(query, (json.dumps(self.data), ))
self.conn.commit()