Category Archives: Uncategorized

SOX and BASH

Bruno torso shell script.

Using SOX to generate random audio video using its spectrogram


#!/bin/bash

n=1;
baseone=$(shuf -i 500-3000 -n 1)
basetwo=$(shuf -i 100-3000 -n 1)

type=$(( $RANDOM % 10 + 1 ))

#type=10

rate=$(shuf -i 1024-192000 -n 1)

wavs=$(shuf -i 4-75 -n 1)

#wavs=10

while [ $n -le $wavs ]
do

filename=note$n.wav
spectroname=spectro$n.png

noteone=$(($baseone + $n * 2))
notetwo=$(($basetwo * $n))

if [ "$type" -gt "5" ]
then
sox -r $rate -n $filename synth 0.5 sine $noteone-$notetwo sawtooth $baseone-$basetwo sin $noteone sin 50-120 spectrogram -o $spectroname
else
reverb=$(shuf -i 1-40 -n 1)
sox -r $rate -n $filename synth 0.5 sine $noteone-$notetwo trapezium $noteone sawtooth $noteone sin $notetwo tremolo 30 reverb $reverb flanger triangle spectrogram -o $spectroname
fi

n=$((n+1))

done

sox /var/www/html/uploads/*.wav out.wav

#create a =nother single wav and mix it with out.wav
otherwavlength=`awk 'BEGIN{printf("%0.2f", '$wavs' * '0.5')}'`
sox -r $rate -n other.wav synth $otherwavlength sawtooth $baseone-$basetwo flanger 0.9 0.9 4.0 0.23 1.3 chorus 0.7 0.9 55.0 0.4 0.25 2.0 -t
sox -m other.wav out.wav new.wav fade p 0 0 2

#rename the png files (0001, 0002, etc)
a=1
for i in *.png; do
new=$(printf "%04d.png" ${a})
mv ${i} ${new}
a=$((a+1))
done

#each image will display for a rate of 2 per second

avconv -y -i new.wav -r 2 -i %4d.png -c:v libvpx -b:v 1M -vf crop=900:585:0:0 -c:a libvorbis bruno.webm

Get a random BBC Headline from the RSS / XML

Get  random headline from the BBC using the DocumentFactory


ArrayList<NewsItem> items = new ArrayList<>();
try{
   DocumentBuilder builder = DocumentBuilderFactory.newInstance()
      .newDocumentBuilder();
   URL u = new URL("http://feeds.bbci.co.uk/news/technology/rss.xml");
   Document doc = builder.parse(u.openStream());
   NodeList nodes = doc.getElementsByTagName("item");
   for(int i = 0; i < nodes.getLength(); i++){
      Element element = (Element) nodes.item(i);
      NewsItem currentStory = new NewsItem(getElementValue(element, "title"),
         getElementValue(element, "description"), getElementValue(element, "link"),
         getElementValue(element, "pubDate"));
      items.add(currentStory);
   }
}
catch(Exception ex){
   if(ex instanceof java.net.ConnectException){
   }
}
Random random = new Random();
NewsItem item = items.get(random.nextInt(items.size() - 1));
return item;

Change Status Bar to Custom Drawable

Change the Android statusbar to a custom drawable on Lollipop devices.

by Napalm.

statusbar

StatusBarView


public class StatusBarView extends View
{
	private int mStatusBarHeight;

	public StatusBarView(Context context)
	{
		this(context, null);

	}

	public StatusBarView(Context context, AttributeSet attrs)
	{
		super(context, attrs);
		if(Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP){
			setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
		}
	}

	@Override
	public WindowInsets onApplyWindowInsets(WindowInsets insets)
	{
		if(Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP){
			mStatusBarHeight = insets.getSystemWindowInsetTop();
			return insets.consumeSystemWindowInsets();
		}
		return insets;
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
	{
		setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),mStatusBarHeight);
	}
}

Values-v21.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

	<style name="AppTheme" parent="BaseAppTheme">
		<item name="android:windowDrawsSystemBarBackgrounds">true</item>
		<item name="android:statusBarColor">@android:color/transparent</item>
	</style>

</resources>

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:tools="http://schemas.android.com/tools"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	android:orientation="vertical"
	tools:context=".MainActivity"
	>
	<com.example.StatusBarView
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:background="@drawable/top_gradient"
		/>
        <!--etc -->
</LinearLayout>

top_gradient.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
	android:shape="rectangle"
	>
	<gradient
		android:type="linear"
		android:startColor="#ff7300"
		android:centerColor="#77000000"
		android:endColor="#000000"
		android:centerX="0.5"
		android:centerY="0.3"
		android:angle="0"
		/>
</shape>

//… etc …

Pidgin Messenger and Google Chat “Not Authorized”

To allow Pidgin Messenger to work with Google chat/Google talk, you must enabled access to less trusted apps.

Login to your Google account and visit this link: https://myaccount.google.com/

Signing in -> Access for less secure apps -> Turn On

Now Pidgin Messenger will connect to Google chat.

Get Version Code from android apk file using aapt

Use aapt to get the version code from an apk

/sdk/build-tools/21.1.2/aapt d badging /path/to/file.apk

Facebook apps for Android: generating hash using keytool

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

(This will generate the hash for your debug keystore, default password = android)

Eclipse OutOfMemoryError

You can increase the amount of memory available to the VM by making the following changes in the eclipse.ini file

-XX:MaxPermSize=500m
-Xms1024m
-Xmx2048m

Tagged , ,

Eclipse: A fatal error has been detected by the Java Runtime Environment

If you get this error when running elcipse then it could be that the webkit access from within eclipse is crashing the program

# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007faa285272a1, pid=6033, tid=140373115860736
#
# JRE version: Java(TM) SE Runtime Environment (8.0_25-b17) (build 1.8.0_25-b17)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.25-b02 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libsoup-2.4.so.1+0x6c2a1] soup_session_feature_detach+0x11
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try “ulimit -c unlimited” before starting Java again
#
# An error report file with more information is saved as:
# /home/brx/hs_err_pid6033.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

SOLUTION:

For me I added to following line to eclipse config.ini and it no longer crashes!

org.eclipse.swt.browser.DefaultType=mozilla

Tagged , ,

Linux Mint 17 Hot Corner open Terminal

Add the following script to ‘Hot Corner’ in order to open a terminal whenever you move your mouse to the corner of the screen


#!/bin/sh
SERVICE='xfce4-terminal'

if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
wmctrl -Fa ‘Terminal’
else
xfce4-terminal
fi

If a Terminal window is already open then it will be brought forward into focus, if not then it will fire open a new one!

Help me with an app Im working on

android manchester

If you have an Android device that is running Android 3 or later (Honeycomb) and you have a spare 5 minutes then please run my test app!

Download the test app: Click Here

At the end of the test you will be asked a few questions, please send me the answers along with the file fftestlog.txt, which can be found on your sdcard in the root directory to carltheandroid@gmail.com or post it on this thread, there is nothing in the information that is at all a security risk its just hardware info mostly. Once the test is finished you can uninstall the app.

What do I do?

Just download the file above using your phone. When asked to install the app say yes**. Once the app has opened run each test by clicking on the “Run Test” button, each test needs to end before the next test button can be touched.. it should take no longer than a couple of minutes to go through each test. The reason the app is asking for camera permissions is because you will be recording a short video, the reason it asks for sdcard permissions is so that it can write the log file to the sdcard.

**when installing the file you might see a notice like “Not allowed to install from third-part/untrusted source”…you need to go into the main menu Settings >> Applications >> Unknown sources and enable this. Basically your phone out of the box will only install from Play Store, this option removes that restriction.

What does the test do?

The test is checking to see whether ffmpeg + libx264 will run on your device with no problems, it does this by recording a short video and then attempting to overlay a jpg to the video (just click the red RECORD button when asked to record the video, recording will stop automatically after about 3 seconds). A text file called fftestlog.txt notes down a few things that I need to know along with the output of cat /proc/cpuinfo.

If you want/need to see the source code just ask.

Thanks.

Tagged