Skip to content

Instantly share code, notes, and snippets.

View sithart's full-sized avatar
😀
The time has come

sitharthan sithart

😀
The time has come
  • Chadura Tech
  • Chennai
View GitHub Profile
@saqib-mehmood-tkxel
saqib-mehmood-tkxel / django_example.py
Last active March 26, 2023 17:42
Code sample of Python/Django
class ApplyCredit(APIView):
permission_classes = [IsAuthenticated]
def post(self, request):
"""
Apply credit on bill.com
"""
try:
audit_log = AuditLog(user=request.user)
billee_id = request.POST.get('billee_id')
@bartmachielsen
bartmachielsen / audit_logging.py
Last active March 26, 2023 17:41
Django Auditlogging in combination with Django rest framework
from __future__ import unicode_literals
import threading
import time
from django.conf import settings
from django.db.models.signals import pre_save
from django.utils.functional import curry
from django.apps import apps
from auditlog.models import LogEntry
>>> from django.contrib.auth.models import User
>>> ContentType.objects.get_for_model(User)
<ContentType: user>
from django.contrib.contenttypes.models import ContentType
from auditlog.models import LogEntry
import json
def get_LogEntry_Journal(self, model, field_name):
content_type = ContentType.objects.get_for_model(model)
@NoraCodes
NoraCodes / work_queue.rs
Last active February 21, 2024 15:27
An example of a parallel work scheduling system using only the Rust standard library
// Here is an extremely simple version of work scheduling for multiple
// processors.
//
// The Problem:
// We have a lot of numbers that need to be math'ed. Doing this on one
// CPU core is slow. We have 4 CPU cores. We would thus like to use those
// cores to do math, because it will be a little less slow (ideally
// 4 times faster actually).
//
// The Solution:
@wizioo
wizioo / gitignore_per_git_branch.md
Last active July 22, 2024 00:18
HowTo have specific .gitignore for each git branch

How to have specific .gitignore for each git branch

Objective

My objective is to have some production files ignored on specific branches. Git doesn't allow to do it.

Solution

My solution is to make a general .gitignore file and add .gitignore.branch_name files for the branches I want to add specific file exclusion. I'll use post-checkout hook to copy those .gitignore.branch_name in place of .git/info/exclude each time I go to the branch with git checkout branch_name.

@dkarchmer
dkarchmer / cognito-developer-authenticated-client-example.py
Last active November 8, 2022 16:12
django-boto3-cognito: AWS' Cognito Developer Authenticated Identities Authflow using Django/Python/Boto3 (For building stand-alone clients)
__author__ = 'dkarchmer'
'''
This script emulates a stand-alone Python based client. It relies on Boto3 to access AWS, but
requires your Django server to have an API for your user to access Cognito based credentials
Because of Cognito, the client (this script) will only get temporary AWS credentials associated
to your user and only your user, and based on whatever you configure your AIM Policy to be.
Most Cognito examples demonstrate how to use Cognito for Mobile Apps, so this scripts demonstrate
how to create a stand-alone Python script but operating similarly to these apps.
@hanksudo
hanksudo / PostgreSQL_Note.md
Last active August 7, 2023 07:41
PostgreSQL Note
@christianroman
christianroman / test.py
Created May 30, 2013 16:02
Bypass Captcha using 10 lines of code with Python, OpenCV & Tesseract OCR engine
import cv2.cv as cv
import tesseract
gray = cv.LoadImage('captcha.jpeg', cv.CV_LOAD_IMAGE_GRAYSCALE)
cv.Threshold(gray, gray, 231, 255, cv.CV_THRESH_BINARY)
api = tesseract.TessBaseAPI()
api.Init(".","eng",tesseract.OEM_DEFAULT)
api.SetVariable("tessedit_char_whitelist", "0123456789abcdefghijklmnopqrstuvwxyz")
api.SetPageSegMode(tesseract.PSM_SINGLE_WORD)
tesseract.SetCvImage(gray,api)
print api.GetUTF8Text()