This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Simple use: | |
#2 argvs filename and search term/word | |
#USAGE below to search the file ElementTree.py for the word 'parse ': | |
#python SearchFile.py ElementTree.py parse | |
import sys | |
filename = sys.argv[1] | |
search = sys.argv[2] | |
#f = open("ElementTree.py") | |
f = open(filename) | |
lines = f.readlines() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Get numpy mean of an image, np meanimage mean as a float image mean as a decimal | |
float is the mean displayed in a value between 0 and 1 | |
""" | |
from skimage import io | |
import numpy as np | |
image = io.imread('http://i.stack.imgur.com/Y8UeF.jpg') | |
print(np.mean(image)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Randomly choose an mp3 from a directory, randomly crop off some of the beginning: start = randint(20,70) | |
This prevents the long silent beginning some mp3s have. Also breaks the exact pattern in case of a | |
duplicate random choise. I use this generated file in another script so I save it with the same name: | |
music/use.mp3 | |
That way I can use the same mp3 name in the app using TwitterPrep.py to generate a new one. | |
""" | |
import subprocess | |
from random import randint | |
import os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import math from turtle import * | |
# The gravitational constant G | |
G = 6.67428e-11 | |
# Assumed scale: 100 pixels = 1AU. AU = (149.6e6 * 1000) | |
# 149.6 million km, in meters. SCALE = 250 / AU class Body(Turtle): """Subclass of Turtle representing a gravitationally-acting body. Extra attributes: mass : mass in kg vx, vy: x, y velocities in m/s px, py: x, y positions in m """ name = 'Body' mass = None vx = vy = 0.0 px = py = 0.0 def attraction(self, other): """(Body): (fx, fy) Returns the force exerted upon this body by the other body. """ # Report an error if the other object is the same as this one. if self is other: raise ValueError("Attraction of object %r to itself requested" % self.name) # Compute the distance of the other body. sx, sy = self.px, self.py ox, oy = other.px, other.py dx = (ox-sx) dy = (oy-sy) d = math.sqrt(dx**2 + dy**2) # Report an error if the distance is zero; otherwise we'll # get a ZeroDivisionError exception further down. if d == 0: raise ValueError("Collision bet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Planet | |
{ | |
float radius; | |
float distance; | |
Planet[] planets; | |
float angle; | |
float orbitspeed; | |
Planet(float r, float d, float o) | |
{ | |
radius = r; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Planet sun; | |
void setup() { size(600, 600); | |
sun = new Planet(50, 0, 0); | |
sun.spawnMoons(5, 1); | |
} | |
void draw() { | |
background(0); | |
translate(width/2, height/2); | |
sun.show(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python | |
""" | |
View the head and as many lines as you wish | |
the last argv 9 will print the head and 7 lines | |
eight lines total | |
Usage: | |
python viewCSVlines.py co2.csv 8 | |
""" | |
import sys | |
filename = sys.argv[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
#filename = "/home/jack/Desktop/deep-dream-generator/notebooks/CSV_DATA/datasets/LakeHuron.csv" | |
#filename = sys.argv[1:] | |
input1 = sys.argv[1] | |
with open(input1) as myfile: | |
head = [next(myfile) for x in xrange(6)] | |
xx = "info :" | |
dd=xx.join(head) | |
print dd |