Skip to content

Instantly share code, notes, and snippets.

View Krewn's full-sized avatar

Kevin Nelson Krewn

View GitHub Profile
@Krewn
Krewn / ex1.py
Last active August 29, 2015 14:09
Exploration of hypothetical function run-times.
import numpy as np
from time import time
from random import random
from pylab import *
counter = {'ci':0,'cj':0,'ck':0,'cfp':0,'hyp':0} #accessing arrays once they are constructed is O(1)
hyp=0
def nlog(base,value):
return(np.log(value)/np.log(base))
def ranRange(n,counterkey):#assume o(n^2)
@Krewn
Krewn / circle.py
Last active August 29, 2015 14:10
A quick doodle, perhaps thought provoking.
import sys
import os
#import and init pygame
import pygame
import numpy
from time import sleep
pygame.init()
scale = 3
def getPos(angle,X,Y,o,i):
@Krewn
Krewn / yacasTools.R
Last active August 29, 2015 14:13
The beginnings of a set of tools to better integrate yacas with R through the Ryacas cran package.
#############################################
#Package is liscensed by #
# KrewnSolutions /< /? [- \/\/ |\| #
#http://dev.perl.org/licenses/artistic.html #
#liscense holder: kpie314(a)gmail.com #
#############################################
library(Ryacas)
x<-Sym("x")
derivToFunc<-function(d){
@Krewn
Krewn / dayOfTheWeek.py
Last active August 29, 2015 14:13
Get day of the week from an integer number for day in the current month.
def getDow(n):
dotw = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Firday","Saturday"] #Days of the week
dow = time.strftime("%A") #Day of the week
c = 0
while(dotw[c]!=dow):
c+=1
dom = time.strftime("%d") #Day of the monthwClock = [a for a in dot]
d = (c+int(dom)+n)%7-1
return(dotw[d])
@Krewn
Krewn / efield.py
Created January 26, 2015 18:09
Electric field visualizer for point charges
import sys
import os
class pointCharge:
def __init__(self):
self.location = {}
self.location['x']=0
self.location['y']=0
self.location['z']=0
self.charge = 0
def setLocation(self,p):
@Krewn
Krewn / isNone.R
Last active August 29, 2015 14:14
Check to see if an array element exists and returning a boolean.
newPointer=function(inputValue){ # see : http://www.stat.berkeley.edu/~paciorek/computingTips/Pointers_passing_reference_.html
object=new.env(parent=globalenv())
object$value=inputValue
class(object)='pointer'
return(object)
}
exDb <- function(t,i,v = F){#Check if element i exists in t
r = F
tryCatch({
temp <- newPointer(t[[i]]) # Attempt to access variable location in question
@Krewn
Krewn / efield2.py
Last active August 29, 2015 14:15
Visualizing electric potentials on a plane with point charges. ( scale axis * k , k = 1/4 pi e0 )
import sys
import os
class pointCharge: #An object with a location and a charge
def __init__(self):
self.location = {}
self.location['x']=0
self.location['y']=0
self.location['z']=0
self.charge = 0
@Krewn
Krewn / gist:2ee40be0f2fee6d37f06
Created March 24, 2015 18:08
Study guide for intro to data structures
<intro>
# Test based Development
# Junit
# Eclipse Debugger
# Inheritance(Is a kind of)
# Composition(Is a part of)
# Try/Catch
</intro>
@Krewn
Krewn / bookMark.py
Created July 11, 2015 18:02
Takes 2 arguments, a name and a link then creates an HTML document locally which redirects to a given link for Icon based book marking.
import sys
name = sys.argv[1]
link = sys.argv[2]
op=''
op+='<!DOCTYPE html>\n'
op+='<html>\n'
op+='<head>\n'
op+='<meta http-equiv="Refresh" content="0;'+link+'">\n'
op+='</head>\n'
@Krewn
Krewn / VField.py
Last active August 29, 2015 14:24
Draws 2d vector fields in python
# __ __ ______ ______ ______ ______ ______
#/\ \ / / /\ ___\ /\ ___\ /\__ _\ /\ __ \ /\ == \
#\ \ \'/ \ \ __\ \ \ \____ \/_/\ \/ \ \ \/\ \ \ \ __<
# \ \__| \ \_____\ \ \_____\ \ \_\ \ \_____\ \ \_\ \_\
# \/_/ \/_____/ \/_____/ \/_/ \/_____/ \/_/ /_/
# kpie314(at)gmail.com
# github.com/krewn -- Artistic License
# ______ __ ______ __ _____ ______
#/\ ___\ /\ \ /\ ___\ /\ \ /\ __-. /\ ___\
#\ \ __\ \ \ \ \ \ __\ \ \ \____ \ \ \/\ \ \ \___ \