Skip to content

Instantly share code, notes, and snippets.

View BastinRobin's full-sized avatar
🔬
Trying Odd's on daily basis ;)

Bastin Robin BastinRobin

🔬
Trying Odd's on daily basis ;)
View GitHub Profile
@BastinRobin
BastinRobin / gist:0cca0e267408e361062a8681d0cc556d
Created September 28, 2016 16:23 — forked from excalq/gist:2961415
Javacript: Set or Update a URL/QueryString Parameter, and update URL using HTML history.replaceState()
// Explicitly save/update a url parameter using HTML5's replaceState().
function updateQueryStringParam(param, value) {
baseUrl = [location.protocol, '//', location.host, location.pathname].join('');
urlQueryString = document.location.search;
var newParam = key + '=' + value,
params = '?' + newParam;
// If the "search" string exists, then build params from it
if (urlQueryString) {
keyRegex = new RegExp('([\?&])' + key + '[^&]*');
@BastinRobin
BastinRobin / conversion.py
Created September 26, 2016 17:00 — forked from AnnamalaiNagappan/conversion.py
python script to convert all python .py files inside the current directory and all its subdirectories into .pyc and remove all .py files
import compileall
import os
# Get current working directory
curr_dir = os.getcwd()
# Compiles all python files to pyc
compileall.compile_dir(curr_dir, force=True)
# Recursively iterates to find .py files and remove them
@BastinRobin
BastinRobin / challenge.md
Last active September 23, 2016 15:32
Build Script Challenge

Build Script Challenge

Write a python or shell script when its executed inside a directory it should convert all python .py files inside the current directory and all its subdirectories into .pyc and remove all .py files

For eg:

base(dir)
   - init.py
   - lib(dir)
     - base.py
  • lib.py
@BastinRobin
BastinRobin / decision-tree.py
Created August 23, 2016 16:08
Decision Tree classifier using Python
"""
Machine Learning Classifier Beginner
Classify if the given features is an apple or orange
"""
from sklearn import tree
features = [[140, 1], [130, 1], [150, 0], [170, 0]] # 0 - orange and 1 - apple
labels = [0,0,1,1] # 0 - Orange and 1 - Apple
clf = tree.DecisionTreeClassifier()
clf = clf.fit(features, labels)
print clf.predict([[150, 0]])
@BastinRobin
BastinRobin / index.html
Created July 21, 2016 07:06 — forked from benjchristensen/index.html
Dynamic Stacked Bar Chart using d3.js
<html>
<head>
<title>Dynamic Stacked Bar Chart using d3.js</title>
<script src="http://mbostock.github.com/d3/d3.v2.js"></script>
<style>
rect.a {
fill: green;
}
rect.b {
fill: orange;
@BastinRobin
BastinRobin / Live.py
Created March 18, 2016 08:42
Python Realtime Graph
""" sampleText.txt
1,2
2,3
3,6
4,9
5,4
6,7
7,7
8,4
9,3
@BastinRobin
BastinRobin / README.md
Created March 11, 2016 17:01
Django URL regex

Common Regular Expressions for Django URLs

A list of comman regular expressions for use in django url's regex.

Example Django URLs patterns:

urlpatterns = patterns('',
@BastinRobin
BastinRobin / twitter.py
Created March 10, 2016 05:01
Twitter Scrap
from bs4 import BeautifulSoup as bs
import re
import urllib2
page = urllib2.urlopen("https://twitter.com/sumantewary")
soup = bs(page)
tweets = soup.findAll("p",{"class":"js-tweet-text"})
@BastinRobin
BastinRobin / dynamic_url.py
Created November 25, 2015 15:58
Django Dynamic URL parameter Query
model = Model.objects
for k,vals in request.GET.lists():
for v in vals:
result = model.filter(**{"%s__in" % k: vals})