Saturday, July 21, 2012
php twitter: undefined index: oauth_token_secret
The problem is that there is an error in the request so you don't get oauth_token_secret in the respond from Twitter. Instead you get an error message.
Turn of php notice by typing the following at the top of the page
error_reporting(E_ALL ^ E_NOTICE);
print_r() the $request_token or $request variable to the screen. It will show you the type of error returned by twitter
print_r($request_token );
An example of the error message when you print the array is "Desktop applications only support the oauth_callback value 'oob' /oauth/request_token?oauth_callback=...."
Go to your app settings on twitter and make the correct settings.
In the case of the above error, set the callback url to the one you send in the request and try again!!
Good Luck.
Tuesday, July 17, 2012
svnserve: Can't bind server socket: Address already in use
I was done setting up svn and i ran "svnserve -d -r path" and got the following:
svnserve: Can't bind server socket: Address already in use.
In my case I had previously set up svn which was already listening on the default port 3690.
I solved this simply by looking for that svn process and killing it.
Grep it on commandline with;
ps -ef | grep svnserve
This will show the running svn process. Just get the processID/number and kill it and you should be set..
e.g sudo kill processID.
svnserve: Can't bind server socket: Address already in use.
In my case I had previously set up svn which was already listening on the default port 3690.
I solved this simply by looking for that svn process and killing it.
Grep it on commandline with;
ps -ef | grep svnserve
This will show the running svn process. Just get the processID/number and kill it and you should be set..
e.g sudo kill processID.
Thursday, July 28, 2011
pg_query(): Query failed: ERROR: invalid byte sequence for encoding "UTF8": 0xe28022
Has anyone been face with this problem while trying some inserts into a postgres DB with some character.
Now this is not actually a posgres error but a php issue with html entity encode and decode functionalities. The same effect will happen on a MySQL db since MySQL and PostGre are fairly similar. This can be resolved by setting the character encoding in the php file to that of the database base. Eg for UTF-8 DB set the following in metadata the php file.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
PHP Warning: pg_query(): Query failed: ERROR: invalid byte sequence for encoding "UTF8": 0xe28022
HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".
HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".
Now this is not actually a posgres error but a php issue with html entity encode and decode functionalities. The same effect will happen on a MySQL db since MySQL and PostGre are fairly similar. This can be resolved by setting the character encoding in the php file to that of the database base. Eg for UTF-8 DB set the following in metadata the php file.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Thursday, June 16, 2011
android application **** has stopped unexpectedly try again. Android development
So I was working on my one of my first android apps and there were no errors but when I ran it I had the emulator telling me this: "Application ***** has stopped unexpectedly try again" then I had to force close it. I realized this happens a when some value is not set in the manifest file. In this my case it was the fact that the app would connect to Internet eventually and I had not set the Internet permissions correctly in the manifest file
So i added this line to on top of the application node in the android manifest xml file: <uses-permission android:name="android. permission.INTERNET" />
So i added this line to on top of the application node in the android manifest xml file: <uses-permission android:name="android.
A simple manifest file will look like this (the fix is i red):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas. android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android. permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_ name">
<activity android:name=".Login"
android:label="@string/app_ name">
<intent-filter>
<action android:name="android.intent. action.MAIN" />
<category android:name="android.intent. category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<manifest xmlns:android="http://schemas.
package="com.example"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.
<application android:icon="@drawable/icon" android:label="@string/app_
<activity android:name=".Login"
android:label="@string/app_
<intent-filter>
<action android:name="android.intent.
<category android:name="android.intent.
</intent-filter>
</activity>
</application>
</manifest>
Thursday, May 5, 2011
Postgres - How to check if an array is empty or not
To check how many rows have an empty array of values for a certain column,
Such as to "select from table where dataset is not null";
by dataset it could be array of values. for instance another select query could be a dataset
e.g. (array(select from table2))
See an illustration below. Hope it helps.
so lets say you have two tables for customers and their favorite foods
customer
ID | name
---------
1 stanley
2 sheldon
3 sarah
favorite_food
ID | customer_id(FK to customer ID)|food_name
------------------------------------------------------------------------
1 3 rice
2 3 wheat
3 1 mango
4 2 orange
--the following query will help to make get all instances of customers with food
--this is based on the fact that array_upper and array_lower functions, on empty arrays return null
select * from customer where array_upper(array(select food_name::text
from favorite_food
where customer_id = customer.id),1) is not null;
--there are other alternative to this solution like the example below.
--In the alternative below "{}" is s string literal that is returned when there are no values in the csv table
select * from customer where not (array(select food_name::text
from favorite_food
where customer_id = customer.id),1) = '{}';
--third alternative is to use regular expressions and this can be done in several ways besides what is shown below;
Feel free to add your options are comment or ask a question ;)
select * from customer where not array_to_string(array(select food_name::text
from favorite_food
where customer_id = customer.id),1) ~ '^$';
--of course you can try to remove the "not" to get the opposite result you know what we do.hope this saves someone some time.
Such as to "select from table where dataset is not null";
by dataset it could be array of values. for instance another select query could be a dataset
e.g. (array(select from table2))
See an illustration below. Hope it helps.
so lets say you have two tables for customers and their favorite foods
customer
ID | name
---------
1 stanley
2 sheldon
3 sarah
favorite_food
ID | customer_id(FK to customer ID)|food_name
------------------------------------------------------------------------
1 3 rice
2 3 wheat
3 1 mango
4 2 orange
--the following query will help to make get all instances of customers with food
--this is based on the fact that array_upper and array_lower functions, on empty arrays return null
select * from customer where array_upper(array(select food_name::text
from favorite_food
where customer_id = customer.id),1) is not null;
--there are other alternative to this solution like the example below.
--In the alternative below "{}" is s string literal that is returned when there are no values in the csv table
select * from customer where not (array(select food_name::text
from favorite_food
where customer_id = customer.id),1) = '{}';
--third alternative is to use regular expressions and this can be done in several ways besides what is shown below;
Feel free to add your options are comment or ask a question ;)
select * from customer where not array_to_string(array(select food_name::text
from favorite_food
where customer_id = customer.id),1) ~ '^$';
--of course you can try to remove the "not" to get the opposite result you know what we do.hope this saves someone some time.
Monday, April 18, 2011
multiple listbox select to get a comma separated value
So you have a list box with multiple selects and you want to get a commma separated value of selected values when the form is submited
It is simple html and some php.
example code:
<form action="" method="POST">
<select multiple name="mypets[]">
<option value="dog">Dog</option>
<option value="cat">Cat</option>
<option value="bird">Bird</option>
<option value="mouse">Mouse</option>
</select>
<input type=submit value=submit></input>
</form>
<?php
$mypets = isset($_POST['mypets'])? $_POST['mypets'] : array();
$pets_csv = implode(',',$mypets);
echo($pets_csv);
?>
explantion:
not there that he emphasis is on the "[]" put on front of the name of the list box
thus we are naming it "mypets[]" instead of say "mypets" so that values are stored in the post variable as and array
The as usually you can use implode to get the comma separated values accordingly.
Hope this helps someone who especially overlooks to add "[]" to the name.
It is simple html and some php.
example code:
<form action="" method="POST">
<select multiple name="mypets[]">
<option value="dog">Dog</option>
<option value="cat">Cat</option>
<option value="bird">Bird</option>
<option value="mouse">Mouse</option>
</select>
<input type=submit value=submit></input>
</form>
<?php
$mypets = isset($_POST['mypets'])? $_POST['mypets'] : array();
$pets_csv = implode(',',$mypets);
echo($pets_csv);
?>
explantion:
not there that he emphasis is on the "[]" put on front of the name of the list box
thus we are naming it "mypets[]" instead of say "mypets" so that values are stored in the post variable as and array
The as usually you can use implode to get the comma separated values accordingly.
Hope this helps someone who especially overlooks to add "[]" to the name.
Wednesday, March 30, 2011
implode() notice: php array to string conversion
the general format of the implode() function are as follows:
i) string implode ( $separator, $array)
ii) string implode ( $array)
iii) string implode ( $array, $separator)
I faced a little problem when “$array” wasn’t just an indexed array
but an associative array (thus array of arrays).
I posted this so I can help someone save 10mins
Solution:
if you have an associative array say $array,
use array_values() as shown in the example below:
implode ( ‘,’, array_values($array))
hope it helps!
S
i) string implode ( $separator, $array)
ii) string implode ( $array)
iii) string implode ( $array, $separator)
I faced a little problem when “$array” wasn’t just an indexed array
but an associative array (thus array of arrays).
I posted this so I can help someone save 10mins
Solution:
if you have an associative array say $array,
use array_values() as shown in the example below:
implode ( ‘,’, array_values($array))
hope it helps!
S
Subscribe to:
Posts (Atom)