Batch converting videos to play on the Nexus 7 using FFMPEG
How to batch convert videos to play on the Nexus 7 using FFMPEG in Python.
mypath = r'path_to_video_files' from os import listdir from os.path import isfile, join onlyfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ] for file in onlyfiles: infile = '"' + mypath + file + '"' outfile = '"' + mypath + file + '.mp4' + '"' ffmpegpath = r'ffmpeg.exe' cmd = r' -i ' + infile + ' -acodec libmp3lame -vcodec libx264 -aspect 16:9 -s 800x480 -ab 128k -b 512k -f mp4 -strict experimental ' + outfile import os os.system(ffmpegpath + cmd)
Starting source:
Passing a datastructure between Android activities as JSON
Passing a data structure between Android activities as JSON using Gson.
In the sending Activity:
//Data Droplet data = new Droplet(); //Create intent Intent intent = new Intent(SendingClass.this, ReceivingClass.class); //Create JSON object from data structure Gson gson = new Gson(); String json = gson.toJson(data); //Add JSON to intent intent.putExtra("json", json); //Start Activity with intent startActivity(intent);
In the receiving Activity:
//Get string String json = extras.getString("json","-1"); //Convert JSON to class Gson gson = new Gson(); Droplet droplet = gson.fromJson(json, Droplet.class);
Where Droplet is defined here.
Going through a xlsx spreadsheet by column in Python
Most examples iterate by row. This one iterates by col.
import xlrd workbook = xlrd.open_workbook('test_file.xlsx') worksheet = workbook.sheet_by_index(0) num_cols = worksheet.ncols - 1 curr_col = -1 while curr_col < num_cols: #Iterate through cols curr_col += 1 col = worksheet.col(curr_col) for cell in col: #Iterate through cells in col print cell.value
Generating a file filled with random characters in Python
Generating a file filled with random characters in Python and printing out the elapsed time.
Output goes in tempOut.txt
#!/usr/bin/python import random import string import time start = time.time() f = open('tempOut.txt', 'w') for i in range(0,100000): line = '' for j in range(0,5000): line += str(random.choice(string.letters)) f.write(line + "n") line = '' f.close() end = time.time() print "Elapsed: " + str(end - start)
Getting a JSON object from DigitalOcean in Java
How to get a JSON object from DigitalOcean. This uses Gson.
Getting the HTTP object.
Inputs:
url: URL to access i.e. https://api.digitalocean.com/v2/droplets/
auth_key: Authorization key from DO.
import com.google.gson.Gson; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; private static InputStream retrieveStream(String url, String auth_key) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet getRequest = new HttpGet(url); getRequest.addHeader("Authorization","Bearer " + auth_key); try { HttpResponse getResponse = client.execute(getRequest); statusCode = getResponse.getStatusLine().getStatusCode(); HttpEntity getResponseEntity = getResponse.getEntity(); return getResponseEntity.getContent(); } catch (IOException e) { getRequest.abort(); } return null; }
Converting the response into a Java object:
InputStream stream = retrieveStream(url, auth_key); Reader reader = new InputStreamReader(stream); Gson gson = new Gson(); Droplets response = gson.fromJson(reader, Droplets.class);
Where Droplets.class is implemented like this and Droplet.class is implemented like this.
C#: Recursively getting a list of files with a specific extension
How to recursively get a list of files with a specific extension in C#.
Inputs:
sDir – Starting directory
SExtension – file extension to filter by
List files – A empty list that is used to keep found files while recursing.
public List<string> getFiles(string sDir, string sExtension, List<string> files) { foreach (string d in Directory.GetDirectories(sDir)) { foreach (string f in Directory.GetFiles(d)) { if (f.EndsWith(sExtension)) { files.Add(f); } } getFiles(d, sExtension, files); } return files; }
Starting Source:
http://stackoverflow.com/questions/929276/how-to-recursively-list-all-the-files-in-a-directory-in-c
Browsing through Amazon’s Top 10 Best Sellers
This project lets you browse through Amazon’s various product categories and view the top 10 sellers for that category. You can browse down into sub-categories as well as up into parent categories.
I wrote this to learn about Amazon’s Product Advertising API. Using the API is simple, especially with the sample code provided by Amazon. Amazon returns a lot of information, so the slightly tricky part was figuring out how to parse the XML to get only the information I need.
RSS Feed Creator with hosting
Need a way to get your audiobooks, open courseware, videos, or other content onto your podcast player? The RSS Feed Maker will take your URLs and convert them into a RSS document and give you a URL to give to your podcast player.
The RSS feed is created with Argotic and the files are hosted on Amazon’s S3 file hosting service.
PyCharm vs Komodo IDE for Python Scripting
Activestate seems to have lost its way with Komodo – their scripting language IDE. It used to be a fast, light, and highly usable IDE that made debugging easy. They went off the rails with version 8- it was mostly a UI re-skin with very unstable code, it crashed frequently, froze when opening certain files, and had extremely slow network access. I called it the ‘so what?’ release. They fixed most of these issues in rev 8.5 but the high memory usage still remains. What soured me was paying for a full version upgrade for what was mostly a buggy UI update.
Lately, I’ve been getting into Python and I’ve discovered JetBrains’ free Python IDE – PyCharm. JetBrains has a moderately priced paid version but what is amazing is that the free version of PyCharm includes a Python debugger. Compare this to Activestate’s free Komodo Edit which does not include a debugger of any sort.
Plus, the paid version of PyCharm includes subscriptions and upgrades for 1 year. Activestate requires you to pay $87 in addition to the price you pay for Komodo for a 1 year subscription.
Besides all the price gouging, I’ve found that the free version of PyCharm is a much better Python editor than Komodo.
Here are some great features in PyCharm that are not in Activestate’s Komodo:
Multiple debug sessions. Want to debug two scripts at the same time? You can do that with PyCharm.
Typing in the file window highlights all files that match any of the characters. Komodo only goes to the first match and that is only if you type really fast. Otherwise it will skip around.
Dropdowns for everything. PyCharm dropdowns are almost as good as Visual Studio. In PyCharm I can define a variable as a list/string/dictionary and every time after that I’ll get all associated methods when I type in the period after the variable. Importing a module? You’ll get dropdowns for all the module members.
Built-in Python package manager, built-in TODO manager, built-in windows cmd console manager (it even lets you have multiple sessions open), and even a built-in repository browser!
A little lightbulb (similar to ReSharper) pops up when there is an error or the code can be improved in some way. Clicking on it shows a list of things it can do to fix or improve the code. It makes the changes for you!
If you are a Komodo Python user, then try PyCharm. You will be pleasantly surprised.