Skip to content

Instantly share code, notes, and snippets.

Avatar
⌨️

Manu Ganji manuganji

⌨️
View GitHub Profile
View CsvExport.cs
// Simple C# csv export class
// found here: https://stackoverflow.com/questions/2422212/simple-c-sharp-csv-excel-export-class/
// I guess copyright is (c) Chris Hulbert https://stackoverflow.com/users/59198/chris
using System;
using System.Data.SqlTypes;
using System.IO;
using System.Text;
using System.Collections.Generic;
View designer.html
<link rel="import" href="../ace-element/ace-element.html">
<link rel="import" href="../chart-js/chart-js.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
View django-crossdomainxhr-middleware.py
import re
from django.utils.text import compress_string
from django.utils.cache import patch_vary_headers
from django import http
try:
from django.conf import settings
XS_SHARING_ALLOWED_ORIGINS = settings.XS_SHARING_ALLOWED_ORIGINS
@manuganji
manuganji / postactivate
Last active Jun 27, 2018 — forked from unbracketed/gist:228457
virtualenv postactivate and postdeactivate files for django. Place these files at $VIRTUAL_ENV/bin. That is inside the bin folder inside the virtualenv directory
View postactivate
#!/bin/bash
# This hook is run after this virtualenv is activated.
# Place this file at $VIRTUAL_ENV/bin
# I usually drop something like this into my virtualenv's postactivate for some
# quick and handy shortcuts to common Django commands.
# This way dropping in to do some work on any arbitrary project is as easy as:
# 1. workon <project name>
# 2. djr
@manuganji
manuganji / django_aggregate_query.py
Last active May 1, 2020
Aggregate query to know percentage of different types in a model
View django_aggregate_query.py
from django.db.models import Count
from models import Animal
all_animal_types = Animal.objects.all().values('animal_type')
num_animal_types = len(all_animal_types)
dict_of_percentages = { animal_type['animal_type']:animal_type['animal_type__count'] * 100/num_animal_types
for animal_type in all_animal_types.annotate(Count('animal_type')) }
print dict_of_percentages
@manuganji
manuganji / height_regex.js
Last active Nov 25, 2019
JavaScript Regex to figure out the value in inches when the input value is in feet-inch notation( Eg: height) . Properly catches 5'10", 11'10", 5'2", 5'07, 5', 5'", 5 Also fails correctly for 5'13", 5'233", 521'1",
View height_regex.js
height_val = $("#id_height").val();
var regex_op = /^(\d{1,2})[\']?((\d)|([0-1][0-2]))?[\"]?$/g.exec(height_val);
//very rare chance for someone to be of two digit feet height.
//but i put it there, just in case.
var feet = regex_op[1];
var inches = regex_op[2];
// converting to inches
var height = (parseInt(feet) || 0) * 12 + (parseInt(inches) || 0);
You can’t perform that action at this time.