Skip to content

Instantly share code, notes, and snippets.

View gamesbrainiac's full-sized avatar
💭
Gone Fishing.

Nafiul Islam gamesbrainiac

💭
Gone Fishing.
View GitHub Profile
@gamesbrainiac
gamesbrainiac / models.py
Created June 9, 2013 08:48
Custom database field in PostManager
def category_posts(self, *args):
all_posts = self.published_posts()
for category in args:
all_posts = all_posts.filter(
categories__category_name__contains=str(category)
)
return all_posts
@gamesbrainiac
gamesbrainiac / base.js
Created June 13, 2013 18:28
Ultra crap js, right here.
$(document).ready(function() {
var dir = $.url(document.URL).attr('directory');
console.log(dir);
var list = $(".nav li a");
for (var i = 0; i < list.length; i++) {
var obj = $(list[i]);
if(dir == obj.attr('href')){
//noinspection JSCheckFunctionSignatures
obj.parent().addClass('active');
}
@gamesbrainiac
gamesbrainiac / #10_4.py
Created June 14, 2013 21:22
Now, this is a beautiful algorithm.
import time
__author__ = 'Nafiul Islam'
__title__ = 'Summation of primes'
# Very slow implementation for some reason
# Modelled after the sieve of Eratosthenes
def main(limit=1000):
@gamesbrainiac
gamesbrainiac / testing.py
Created June 20, 2013 14:55
Learning SQL! :D
def query():
cursor = db.execute("SELECT * FROM links WHERE submitter_id=62443 ORDER BY submitted_time ASC")
assert isinstance(cursor, sqlite3.Cursor)
return_links = [Link(*link).id for link in cursor.fetchall()]
return return_links
@gamesbrainiac
gamesbrainiac / ajax.js
Created June 29, 2013 19:42
Awesome getCookie Function from djangoproject
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
@gamesbrainiac
gamesbrainiac / info_getter.py
Created July 22, 2013 20:17
Super awesome python code.
import requests
def get_raw_repo_data(username):
"""
Creates a connection to api.github.com through HTTPS
"""
print('starting')
CONNECTION_DETAILS = {
"host": "https://api.github.com",
"path": "/users/" + username + "/repos",
from collections import defaultdict
from heapq import *
def prim( nodes, edges ):
conn = defaultdict( list )
for n1,n2,c in edges:
conn[ n1 ].append( (c, n1, n2) )
conn[ n2 ].append( (c, n2, n1) )
mst = []
@gamesbrainiac
gamesbrainiac / Auto generate requirements
Created February 5, 2014 15:49
Automatically generates the requirements of your interpreter through a pip freeze.
# encoding=utf-8
__author__ = 'Quazi Nafiul Islam'
import sys
import pip
if __name__ == '__main__':
sys.stdout = open('requirements.txt', 'w')
pip.main(['freeze'])
function goinit {
export GOROOT=/usr/local/Cellar/go/1.2.1/libexec
if [ $# -lt 1 ]
then
echo "No directories were created."
export GOPATH=$(pwd -P)
export PATH=$PATH:$GOPATH:$GOPATH/bin
else
echo "$1 being created"
mkdir $1
@gamesbrainiac
gamesbrainiac / pipreq.py
Created April 27, 2014 18:11
Pip requirements generator
# encoding=utf-8
# FILE INFO #####################################################
# Title : pip requirements generator
# By : Quazi Nafiul Islam <gamesbrainiac@gmail.com>
# Date : 28 Apr 2014
# Made to be used with pycharm Macros
#################################################################
import pip