Skip to content

Instantly share code, notes, and snippets.

View BlogBlocks's full-sized avatar

Jack Northrup BlogBlocks

View GitHub Profile
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()
@BlogBlocks
BlogBlocks / trasa.geojson
Created December 5, 2017 06:14
geojson
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@BlogBlocks
BlogBlocks / FFMPEG.ipynb
Last active December 19, 2017 00:24
ffmpeg jupyter notebook. everything works fine video maker.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@BlogBlocks
BlogBlocks / Python_image_mean.script
Last active December 19, 2017 00:25
finding an image mean
"""
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))
"""
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
@BlogBlocks
BlogBlocks / orbits.py
Created December 2, 2017 19:58
orbits
#!/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
@BlogBlocks
BlogBlocks / planet.pde
Created December 2, 2017 19:23
planer
class Planet
{
float radius;
float distance;
Planet[] planets;
float angle;
float orbitspeed;
Planet(float r, float d, float o)
{
radius = r;
@BlogBlocks
BlogBlocks / Sun.pde
Last active December 2, 2017 19:11
Processing solarsys SUN
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();
#!/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]
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