Archive
Subscribe to mailchimp via API in PHP
This is a handy little PHP script using CURL that adds an email address onto a MailChimp list
taken from: https://apidocs.mailchimp.com/api/1.3/listsubscribe.func.php
<?php
$apiKey = ‘xxxxxx’; // your mailchimp API KEY here
$listId = ‘xxxxx’; // your mailchimp LIST ID here
$double_optin=false;
$send_welcome=false;
$email_type = ‘html’;
$email = $_POST[’email’];
//replace us2 with your actual datacenter
$submit_url = “http://us10.api.mailchimp.com/1.3/?method=listSubscribe”;
$data = array(
’email_address’=>$email,
‘apikey’=>$apiKey,
‘id’ => $listId,
‘double_optin’ => $double_optin,
‘send_welcome’ => $send_welcome,
’email_type’ => $email_type
);
$payload = json_encode($data);$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $submit_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($payload));$result = curl_exec($ch);
curl_close ($ch);
$data = json_decode($result);
if ($data->error){
echo $data->error;
} else {
echo ‘Got it, you\’ve been added to our email list.’;
}
?>
Premature end of script headers
I’m not really used to fixing problems on Linux / Apache – but after a server crash, and a forced migration to a new server, I’ve had to get my hands dirty and try and get a new Linux server back up and running.
So, my problem was. I needed to install Perl, Python and Ruby on the server, I had existing scripts but nothing appeared to work, I just got the generic Http 500 Internal server error message. – Which isn’t enough to work with.
The first step with troubleshooting is to get more information on the error, which means in my case anyway, looking at the file /var/log/httpd/error_log (I’m on centOS), and looking at the last error.
Then fixing the error listed
Permission denied: exec of ‘….HelloWorld.py’ failed
This means you need to grant execute permissions to the file, – i.e. in WinSCP, right click the file, select properties, then click all the X checkboxes in permissions
Premature end of script headers: HelloWorld.py
This means, in my case anyway, was the shebang line was pointing to the wrong file – so instead of
#!usr/local/bin/python it was in fact #!usr/bin/python
You can type which python into the command prompt to find the location of your python executable
: undefined method `require_relative’ for main:Object
This was a ruby specific error I got, which was because I had an old version of Ruby installed (1.8.1), just replaced require_relative to require, and that went away.
Localise a web page via Javascript
Here is a way to simply detect the user’s language,and switch the content for the local version. As a caveat, this system will show English before changing to the local language, and it’s not good for SEO. You can get rid of the change from english by removing visible text in the HTML, but this also serves as a failover for users who don’t speak any of the supported languages.
<span id=”btnBuy”>Download Software</span>
<script language=”javascript”>
var translations = {
“en” : {
“btnBuy” : “Download Software”
},
“fr” : {
“btnBuy” : “Télécharger le logiciel”,
}};function changelanguage(httpheaders)
{
var lang=httpheaders[“Accept-Language”];
lang = lang.split(“,”)[0].substring(0,2);
console.log(lang);
for(var i in translations[lang])
{
var translation = translations[lang][i];
console.log(i + “->” + translation);
document.getElementById(i).innerHTML = translation;
}
}
</script>
<script src=”http://ajaxhttpheaders2.appspot.com/?callback=changelanguage”></script>
Kudos to Dan Singerman for the appengine script.
Free UK VPN (L2TP – suitable for iPad)
vpn-td2.reliablehosting.com
Login:vpn527
Password:zGGZ8q8kE6
L2TP key:dARkaTt25rW4fqBC
Server:91.228.115.130
Not using this server for the rest of the month, so feel free to use it!
Automated access_token grant using Facebook and C=
Say you wanted to get an access token for facebook from a desktop app, but don’t want to display the normal facebook login screen. – and you somehow know the user’s facebook username and password – then this approach might help you get the access token you need;
first, you need to set up a facebook app, and get the client_id
public void GetAccessToken(Action<string,string> Callback)
{
this.Callback = Callback;
string strUrl = “https://www.facebook.com/dialog/oauth?”;
strUrl += “type=user_agent&”;
strUrl += “client_id=xxxx&”;
strUrl += “redirect_uri=xxxxx”;
this.webBrowser1.DocumentCompleted += WebBrowser1OnDocumentCompleted;
this.webBrowser1.Navigate(strUrl);
}
Here, I’m assuming you have a windows form, with a web browser control called webBrowser1 – redirect_uri has to be whatever was configured in the facebook app, but other than that, it doesn’t matter.
then we fill out the username / password and click the login burron on Document completed;
private void WebBrowser1OnDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs webBrowserDocumentCompletedEventArgs)
{
if (webBrowser1.Url.Host == “<domain>”)
{
var variables = HttpUtility.ParseQueryString(webBrowser1.Url.Fragment);
var access_token = variables[“#access_token”];
var expires_in = variables[“expires_in”];
Callback(access_token, expires_in);
}
else
{
var strJs1 = @”document.getElementsByName(’email’)[0].value ='” + strUsername + “‘”;
var strJs2 = @”document.getElementsByName(‘pass’)[0].value = ‘” + strPassword + “‘”;
var strJs3 = @”document.getElementsByName(‘login’)[0].click()”;
SendJs(strJs1);
SendJs(strJs2);
SendJs(strJs3);
}
}
SendJS is defined as follows;
protected string SendJs(string jScript)
{
object[] args = { jScript };
var strReturn = webBrowser1.Document == null ? “” : webBrowser1.Document.InvokeScript(“eval”, args);
System.Diagnostics.Debug.WriteLine(jScript);
System.Diagnostics.Debug.WriteLine(strReturn);
return strReturn == null ? “” : strReturn.ToString();
}
You’ll also need the following global variables
public string strUsername = “<email>”;
public string strPassword = “<password>”;public Action<string, string> Callback;
Hope this helps someone out!
Changes to Linkedin API
|
||||||||||
|
|
||||||||||
|
Using Html5 geolocation to find someone via their email
Here’s a tool that you can use to track the location (lat/lon) of someone via their email account:
Offline Adverts.com – an advertising solution that works even when offline.

Offline Adverts.com is an advertising platform for apps that is designed to work specifically when the user’s device is offline, and not connected to the Internet. This is where most ad platforms just show an empty space, this backup solution allows you to fill that unused ad space with a paid ad.
As an advertiser, it lets you gain brand exposure, even for a fraction of the cost of the mainstream ad networks.
Want to find out more? visit – OfflineAdverts.com
Open Native Google Maps App from Phonegap / Cordova (iOS)
If you want to show a map in your Phonegap app, you can always use the google maps API to show a map, or even use the in-app browser to link out to a google map page. But nothing quite matches the Google maps native app, with it’s funky satnav-like features, and slick interface
Thing is, the Google Maps App isn’t installed by default, so in this case, I’m failing-over to a in-App Browser version. This code is iOS only, but anyone wishing to provide a port to Android will be rewarded* (Yes, I’d pay for the port)
– (void) openGoogleMaps:(CDVInvokedUrlCommand *)command
{
NSLog(@”openGoogleMaps”);
NSString* callbackId = [command callbackId];
NSArray* arguments = [command arguments];
NSString* map = [arguments objectAtIndex:0];
CDVPluginResult* result;
NSURL *testURL = [NSURL URLWithString:@”comgooglemaps://”];
if ([[UIApplication sharedApplication] canOpenURL:testURL]) {
NSString *directionsRequest = [NSString stringWithFormat:@”%@%@”,
@”comgooglemaps://?” ,
map];
NSURL *directionsURL = [NSURL URLWithString:directionsRequest];
[[UIApplication sharedApplication] openURL:directionsURL];
result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
messageAsBool:true];
} else {
NSLog(@”Can’t use comgooglemaps:// on this device.”);
result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
messageAsBool:false];
}
[self success:result callbackId:callbackId];
}
Then, this is called from Javascript as follows:
function openGoogleMaps(route)
{
console.log(“openGoogleMaps”);
cordova.exec(function(data)
{
console.log(“Returned from google maps:” + data);
if (!data)
{
// Failed to find native app.
var strUrl = “http://maps.google.com/maps?”;
strUrl += route;
var ref = window.open(strUrl, “_blank”, “location=yes”);
}
}, function(data)
{
console.log(“Plugin failure”);
}, ‘StatusBar’, ‘openGoogleMaps’, [route]);
}
Upload a file to Amazon S3 using C#
This code example is probably online a million times, but just to include it again here;
string existingBucketName = “mybucket”;
string filePath = @”c:\users\you\desktop\file.png”;
Amazon.Util.ProfileManager.RegisterProfile(“test”, “xxxxx”,”XXXX”);
AWSCredentials credentials = new StoredProfileAWSCredentials(“test”);
IAmazonS3 s3Client = new AmazonS3Client(credentials, RegionEndpoint.EUWest1);
TransferUtility fileTransferUtility = new TransferUtility(s3Client);
var uploadRequest = new TransferUtilityUploadRequest
{FilePath = filePath,
BucketName = existingBucketName,
CannedACL = S3CannedACL.PublicRead
};
fileTransferUtility.Upload(uploadRequest);
