Skip to content

Instantly share code, notes, and snippets.

View aatishnn's full-sized avatar

Aatish Neupane aatishnn

View GitHub Profile
@aatishnn
aatishnn / binarymaxheap.c
Last active June 3, 2021 07:24
Priority Queue and Max-heap implementation in C (Inspired from https://gist.github.com/martinkunev/1365481)
// Array representation according to Wikipedia article but starts from 0 index.
#include <stdio.h>
#include <stdlib.h>
struct heap {
int size;
int count;
int *heaparr;
};
@aatishnn
aatishnn / sort.c
Last active January 3, 2016 00:19
Different sorting algorithms implementation
#include <stdio.h>
#include <stdlib.h>
void isort(int a[], int len) {
int key, i,j;
for(i=1; i < len; ++i) {
key = a[i];
for(j=i-1; j>=0 && key < a[j]; --j) {
a[j+1] = a[j];
}
@aatishnn
aatishnn / priority_circular_queue.c
Created November 27, 2014 12:15
Priority Circular Queue (Priority Queue inside Circular Queue) Implementation in C
#include <stdio.h>
#include <stdlib.h> // For qsort
#define QUEUESIZE 10 // Number of items the Queue can hold
typedef enum { false, true } bool; // Use #include <stdbool.h> if available
typedef struct {
char name[10];
int priority;
} Item;
@aatishnn
aatishnn / missionaries-cannibals-solver-grapher.py
Created December 28, 2015 01:16
Uses BFS to search for the solution of "missionaries and cannibals" problem. Generates a PNG file of the search tree using GraphViz and PyDot.
from collections import deque
import pydot
class State(object):
""" Initialize state with missionaries and cannibals at
left hand side. Boat=1 means boat is on the left hand side
and Boat=0 means boat is on the right hand side
"""
def __init__(self, missionaries, cannibals, boat, by_move):
self.missionaries = missionaries
@aatishnn
aatishnn / tdp.py
Created February 8, 2016 15:21
Top Down Parser
from prettytable import PrettyTable
epsila = '@'
'''
S -> ABC
A -> abA | ab
B -> bD
D -> CD | @
C -> c | cC

Configure internet on existing HeNN LTSP systems

Collect following variables from the main LTSP server's /etc/ltsp/dhcpd.conf .

  • client_ip_range
  • dns_server
  • broadcast_address
  • routers
  • subnet_mask
@aatishnn
aatishnn / get_poi.py
Created April 19, 2018 12:21
Get CSV of POI around an Area using Google Maps API
import time
import csv
import googlemaps
types = ['airport', 'amusement_park', 'bank', 'bus_station',
'shopping_mall', 'gas_station', 'hospital', 'department_store']
useful_fields = (
'id', 'formatted_address', 'place_id', 'types', 'name', 'rating')
extra_fields = ('latitude', 'longitude', 'poi_type')
@aatishnn
aatishnn / clean_data.py
Created April 21, 2018 12:50
Delete datavalue and complete registration from DHIS2 database based on given Nepali period
"""
Delete datavalue and complete registration from DHIS2 database based on
given Nepali period
Requirements:
- SqlAlchemy
- psycopg2-binary
"""
from sqlalchemy.ext.automap import automap_base
@aatishnn
aatishnn / celery_tasks_error_handling.py
Created May 10, 2018 11:04 — forked from darklow/celery_tasks_error_handling.py
Celery tasks error handling example
from celery import Task
from celery.task import task
from my_app.models import FailedTask
from django.db import models
@task(base=LogErrorsTask)
def some task():
return result
class LogErrorsTask(Task):
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import datetime
import logging
import six
from .compat import python_2_unicode_compatible
from .accessor import Accessor
from .util import generate_message_control_id
logger = logging.getLogger(__file__)