Skip to content

Instantly share code, notes, and snippets.

View mentix02's full-sized avatar
💻
coding away

Manan mentix02

💻
coding away
View GitHub Profile
@mentix02
mentix02 / list.py
Created December 12, 2018 03:41
updates listing of directory every n second
#!/usr/bin/python3
from os import listdir
from time import sleep
from argparse import ArgumentParser
parser = ArgumentParser(description='updates listing of directory every n second')
parser.add_argument('-d', '--directory', default='.', help='directory to list')
parser.add_argument('-t', '--time', type=int, default=1, help='number of seconds to update listing')
parser.add_argument('-n', '--number', type=int, default=10, help='number of times to list directory')
@mentix02
mentix02 / word_counter.py
Last active November 23, 2018 06:37
counts the words in a given file for college essays
def count(limit=350):
file = open('words.py', 'r+')
words = file.read().split()
length = len(words)
if length > limit:
print("word count over word limit")
print(f"words to cut down {length - limit}")
elif length <= limit:
print("word count adheres to word limit")
#!/usr/bin/python3
from time import time
from argparse import ArgumentParser
__version__ = '1.0.0'
parser = ArgumentParser(description='a simple collatz sequence solver')
parser.add_argument('n', help='number', action='store', type=int)
parser.add_argument('-t', '--time', help='show time taken', action='store_true')
@mentix02
mentix02 / religion_sort.py
Created November 10, 2018 08:46
a joke sort that converts all a items in a list to just one
from random import shuffle
data = list(range(1, 100))
shuffle(data)
count = 0
while count != len(data):
data[count] = 1
# inspiration - https://stackoverflow.com/a/2587513/7086106
# original - https://gist.github.com/mentix02/f1d545243b7eb37f7d033fc0735ec868#gistcomment-2754082
fields = """title = models.CharField(max_length=50)
content = models.TextField()
description = models.TextField(blank=True, null=True)
thumbnail = models.ImageField(upload_to='post_thumbnails')
draft = models.BooleanField(default=False)
slug = models.SlugField(blank=True)
author = models.CharField(max_length=30, default='mentix02', blank=True)
@mentix02
mentix02 / model_fields_sorter.py
Last active November 29, 2022 19:10
when developing a django model, I was cleaning up my code when I saw how messy the model fields look. So I implemented a sorting function.
from collections import OrderedDict
def sort_model_fields(fields):
print("BEFORE\n")
print(fields)
# creating a dictionary with key as length of string and value as the string itself
dict_fields = {}
#include <fstream>
#include <iostream>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <unordered_map>
using namespace std;
@mentix02
mentix02 / expanded_form.py
Last active August 24, 2018 17:35
an online challenge to display a number in its expanded format
def expanded_form(num):
number = list(str(num))
zeroes = len(number) - 1
last = number[-1]
ans = []
for index, num in enumerate(number):
if num == '0':
zeroes -= 1
continue
temp = "{} + ".format(int(num) * (10 ** zeroes))
from post.models import Post
from django.http import JsonResponse
from django.views.generic import View
from django.contrib.auth.mixins import LoginRequiredMixin
class PostLikeView(LoginRequiredMixin, View):
@staticmethod
def get(request):
@mentix02
mentix02 / ajax-like.js
Last active June 21, 2018 06:16
an ajax call to update vote
$(function(){
$('.likeButton').click(function(){
let pk = this.id;
$.ajax({
url: '/post/like/',
type: 'POST',
data: {
pk: pk,
},
success: function(data) {