Dengar's Blog Logo

Dengar's blog...
We will see what I post, probably will be some random tutorials

Sunday, 8 January 2012

Auto Download File From FTP - then rename

A little while ago my friend asked me to help him with some Windows commandline scripting. Basically he was waiting for ages for the development team in his company to sort this simple task out and asked me how he can every day automatically download a file from FTP, then rename it with the current date.

I don't do Windows very much and Linux is just much better for exactly these things, but this seemed like an easy enough challenge.

In the end I didn't manage to do everything in one file, but I think that two should work just as well when you add them to the Windows task scheduler...

Here are the files with some explanation:

downloader.bat:

@ftp -i -s:"%~f0"&GOTO:EOF
open ftp.someserver.com
[username]
[password]
!:--- FTP commands below here ---
mget "*.*"
disconnect
The first line starts the windows command line FTP client and the parameters essentially say that everything else in the file should be ignored by the command line itself, but be parsed to the FTP client.
Line two opens the connection and line three and four will send the authentication details. Line six gets all files in the current directory. You could really do here anything you want on the remote and local server, eg: change the local directory path (lcd ...), the remote one (cd ...) send files (put) or even delete them (rm). At the end, I simply disconnect.

renamer.bat:
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "SomeFileName.txt" SomeFileName_%%f-%%e-%%d.txt
In one line: I'm starting a for-loop and I use a tokeniser to delimit the following string into 5 (1-5) sections. %%d specifies the beginning character used for the token (d) and all that follow will be e,f,g...
then I use the %date% (in ("%date%") function to get the current date. Now, In the do part, I will rename the file from SomeFileName.txt to SomeFileName_yyyy-MM-dd.txt

I hope this makes sense and helps a few people. Best of luck...

Saturday, 29 October 2011

Script to disable & enable touchpads

I constantly touch the touchpad when I type. I also normally use an external mouse when I'm on my laptop. I seldom really need it, but I will sometimes want to switch it on (or off).

First you need to find the name of your touchpad in the xinput list:

$ xinput list
⎡ Virtual core pointer                     id=2 [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer               id=4 [slave  pointer  (2)]
⎜   ↳ Razer Razer Imperator                   id=10 [slave  pointer  (2)]
⎜   ↳ Razer Razer Imperator                   id=11 [slave  pointer  (2)]
⎜   ↳ PS/2 Mouse                               id=13 [slave  pointer  (2)]
⎜   ↳ AlpsPS/2 ALPS GlidePoint                 id=14 [slave  pointer  (2)]
⎣ Virtual core keyboard                   id=3 [master keyboard (2)]
    ↳ Virtual core XTEST keyboard             id=5 [slave  keyboard (3)]
    ↳ Sony Vaio Keys                           id=6 [slave  keyboard (3)]
    ↳ Video Bus                               id=7 [slave  keyboard (3)]
    ↳ Power Button                             id=8 [slave  keyboard (3)]
    ↳ USB 2.0 Camera                           id=9 [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard             id=12 [slave  keyboard (3)]

So in my case the touchpad is most likely: PS/2 Mouse on id 13.

You can easily identify if the device is "on" (enabled):
$ xinput list-props "PS/2 Mouse" 
Device 'PS/2 Mouse':
Device Enabled (144): 1
Coordinate Transformation Matrix (146): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
Device Accel Profile (267): 0
Device Accel Constant Deceleration (268): 1.000000
Device Accel Adaptive Deceleration (269): 1.000000
Device Accel Velocity Scaling (270): 10.000000
Evdev Axis Inversion (271): 0, 0
Evdev Axes Swap (273): 0
Axis Labels (274): "Rel X" (154), "Rel Y" (155)
Button Labels (275): "Button Left" (147), "Button Middle" (148), "Button Right" (149), "Button Wheel Up" (150), "Button Wheel Down" (151)
Evdev Middle Button Emulation (276): 0
Evdev Middle Button Timeout (277): 50
Evdev Wheel Emulation (278): 0
Evdev Wheel Emulation Axes (279): 0, 0, 4, 5
Evdev Wheel Emulation Inertia (280): 10
Evdev Wheel Emulation Timeout (281): 200
Evdev Wheel Emulation Button (282): 4
Evdev Drag Lock Buttons (283): 0
 Now create yourself a little file (eg: "touchpad"):

# toggle synaptic touchpad on/off
SYNSTATE=$(xinput list-props "PS/2 Mouse" | grep Enabled | grep -Eo '.$')
if [ $SYNSTATE = 0 ]; then xinput set-int-prop "PS/2 Mouse" "Device Enabled" 8 1
else xinput set-int-prop "PS/2 Mouse" "Device Enabled" 8 0; fi
dengar@dengar-vaio:/usr/bin$ $ xinput list-props "PS/2 Mouse" 

This should sort you out. Don't forget to  change the name of your actual device, remember mine is "PS/2 Mouse"

Next you need to make the file executable:

sudo chmod +x touchpad

Now, to have that file available from the command line, simply copy it to /usr/bin.

Sunday, 4 September 2011

eConsultancy Paid Content

eConsultancy is one of the most renown blogs in the industry. Although eConsultancy staff insist that it is so much more than a blog, it really boils down to the articles that are emailed to you on a daily basis.
Also there are simply too many posts to look at and there are so many that are just blatant agency advertisements, it remains a referred to resource.

What often annoyed me is that, as a free user, you can't download their PDF documents. There are best practise guides and research papers advertised at horrendous prices. As a free user you only get a little teaser, so you never know if it's any good. 

Since a little while now, I have a paid account that is sponsored by my company. I have flicked through these precious PDFs and can assure you: it's not worth paying for. If you still want to read them, I have some here for free that I share with you :)..


Let me know if there are any missing...

Thursday, 23 June 2011

Facebook on the decline

It seems to me that it is set in stone: eConsultancy says it and even the Metro confirms it, the end of facebook has started. And it is welcome news indeed and it should have come much sooner. I can't wait for the time I don't have to read the blatant lies and white washing that is all to prominent in the marketing industry's media.

Digital publications


I have always disliked, but somehow, maybe because I enjoy being cynical, still read the articles in the online marketing press and blogs. Or maybe I was indeed looking for a change in this crappy platform for customer engagement and relatinship management; looking for the recipe of how to make it work, but I never found it..

One of such publications, the latest issue of Figaro Digital, arrived at my desk not too long ago and it was full of facebook junk. I understand that it is a buzz at the moment and that it represents, thanks to limiting API access to selected agencies, a gold mine for digital agencies that found themselves in need for clients as more and more SMBs would take their search marketing in house. Yes, agencies understand how to peddle dung! Three or more pages full of people that claim to understand social media and how to manage it with little columns of half-wisdom, but then: Martin B. With his outrageous claim: "It isn't outside the realm of possibility to suggest that one day facebook will be the internet."

Sure, it isn't outside the realm of possibility, it isn't outside the realm of possibility to suggest that one day man will be born with wings on their back we are all flying and and humankind is enslaved by man-bear-pigs, but you still have to be an imbecil to realistically sugget such a future vision.
But Figaro printing crap is no news to me. In a former role I was working alongside a Marketing Director who wrote the article 'Standing on the Shoulders of PPC Giants'. While this wasn't an agency, it was written to encourge SMBs to join the marketplace and forget doing their own PPC. Of course, joining a marketplace is not a bad idea and this marketplace doing SEM for your products is a great way for both parties to sell products, but this obviously shouldn't deter SMBs from doing their own search engine marketing. It is easy and effective!
Sadly it isn't just Figaro that sells out their good name. eConsultancy has it's fair share of guest blogger that promote their own ideas and flog their own agenda. It is just too tempting to get other people to do your work for you free of charge. Their reputation won't suffer as much, users are well aware that they are reading opinions and advertorials on their site.

The selling data game


The other thing that is shocking to see is how much anonomous data facebook sells. Well, when I say sells, they make these regbporting APIs available to their selected agencies only. These then sell the facebook advertising on to their clients. Agency and facebook are winning. The client however is left with a feeling of tapping into new audiences, wondering if they found a cheap way of building brand awareness. Having been in a meeting the other week with an agency that actually makes this data available, I think a lot of facebook users would think twice about using the site altogether.

Facebook knows this and with all likelihood hopes that their users stay unaware of this for some time to come.
Paying for likes
Yes, most companies tried facebook advertising. Either direct or through an agency. Your direct response / acquisition campaign was in all likelyhood unsuccessful and when you indeed tried it through an agency you would have received the suggestion to instead of getting traffic through to your site, you should acquire fans for your brand and use facebook as a tool to communicate with these people.

Beware, something went majorly wrong here! Instead of getting cold hard marketing leads that are measurable in terms of ROI from your advertising budget, you are trading it for - mmm - a bunch of extra people that you have to manage a relationship with on a platform that is difficult to control.

Today I was looking at an agency's report on how one of our campaigns is performing. New in this report: facebook doesn't allow the tracking of fans anymore, so we now measure the cost-per-like... £1.90.
I think it will take the next generation of martketers to figure out how you turn 'likes' into money.

The slow demise


It will take a long time and lots of 'internal restructuring' till facebook is really out of the marketing world and the majority of people currently working for it will be laid off or have moved on, but it is the beginning. As an advertising platform, it never performed and always seemed like a waste of time and effort. Yes, there are other opportunities for facebook to monetise. Selling their users data, one way or another, in bright daylight or the sneaky way.

As for the private investors, I believe they will get the big money when facebook floats. But take a good hard look at facebook and decide if you want to put your money in the concept of people "liking" things, by clicking on something out of pure boredom.


Not all is bad

No, facebook is a useful tool! It is ideal for viral marketing, managing reputation or making announcements. However, you do want to keep the majority of this communication in and on your own domain, simoly because you own and control it.
All these activities should be free and I believe they currently are. I believe facebook won't be earning money on these now or in the future.

Tuesday, 10 May 2011

Some simple MySQL date-time functions

I often need the first of the month, the last of the month or how many days are in the month for reporting and forecasting purposes.

You can, of course, like myself in the past look up how these things are done every time you need them. But this gets frustrating and it's often easier to surround yourself with your set of own SQL-functions that give you what you need and are easy to remember.

For this purpose I give you:

  1. First of the month date:
  2. drop function if exists fn_getFirstOfMonth;
    create function fn_getFirstOfMonth(date_ datetime) returns datetime
    begin
    set @dater = date_;
    set @dater = DATE_FORMAT(@dater ,'%Y-%m-01');
    return @dater;
    end
  3. Last of the month date:
    drop function if exists fn_getLastOfMonth;
    create function fn_getLastOfMonth(date_ datetime) returns datetime
    begin
    set @dater = date_;
    set @dater = DATE_FORMAT(last_day(@dater) ,'%Y-%m-%d');
    return @dater;
    end
  4. Days in the month:
    drop function if exists fn_getDaysInMonth;
    create function fn_getDaysInMonth(date_ datetime) returns int
    begin
    set @dater = date_;
    set @dater = day(last_day(@dater));
    return @dater;
    end

Do let me know if there are other MySQL date and time functions that you would like to know.
Happy to post them here...

Saturday, 7 May 2011

Can I have some Thetan for my sandwich? - Buying religion off the shelf religion from the street

Scientologists, although not quite often recognised, have been flogging their religion on the streets for many decades now. And why not? - Other cults and religions are doing it too. Mormons, Heavens Gate and even the Manson Family have successfully advertised their ideology through direct promotion, they know the system works.

I believe people are naturally curious, but would be more careful when they know they are being 'evaluated' by a religious cult, so to circumvent the initial resistance that they would have to overcome, Scientology doesn't advertise with it's name, in fact, nothing at their meet stand indicated that they are in any way pursuing another agenda than offering a 'free stress test' and a giant book to help you through it.

Anyways, there I was, coming out of the tube and seeing the Scientologist stand right in front of the station. I was ready to be Scientologied.

"So this device checks how stressed I am by passing an insignificant amount of electricity through my body?"
I am surprised though how many people go for the "free stress test" offered by L. Ron Hubbard's minions though. I remember the 'Churches' earlier recruitment efforts required their subjects to undergo a more detailed test, that can still be taken online. It's a fun thing to do when you have absolutely nothing to do for 16 hours of your life. Feel free to do it here.
This time I was promised that the Free Stress Test would last only four minutes.

Soon enough I was handed the handles of the E-Meter, a device that measures changes in the electrical resistance of your body and the conductance of your skin by passing a very tiny current through your body. It did take a while, talking about various levels of potentially stress inducing scenarios until my tester, through turning and twisting of various dials, managed to get the needle to swing. I think about 4 minutes, in fact. It must've helped that my hands started to get a bit sweaty, after all that does increase the conductance of my skin. The result: yes, I am stressed - what a surprise.

My antidote was purchasing the Dianetics DVD and book for the little sum of £20. Since I always wanted to have a gander, I negotiated the price down to £5 for the book only, but I am afraid I have not had the chance to flick through it. After the sale, I was of course encouraged to give my name, address and email to the lead Scientologist, but I only left my first name and an old email address that I haven't used in a long time.
Your soul is possessed by this volcano and only Tom Cruise will be able to show you the way.
I did take the book home, but I was rather surprised when I saw it sodomising actual literature, see here how it forcibly engulfs my favourite book, Cannery Row by John Steinbeck.

Bad El-Ron! Down! Leave the Cannery Row alone!
It did seem rather popular with the crowd in front of this London tube station at 8.30 in the evening. Maybe buying religion off the shelf is a huge business? Maybe I should create a religion eCommerce shop where you can create your own religion by mix and match? Eg: mix some Judaism with Buddhism, top it up with Greek Mythology and sprinkle some Heaven's Gate over it. £350,000.
See, that's the clever thing about my religion shop: the product is easy to produce and even easier to source, but if you do pay THAT kinda money, you will treasure it...

Thursday, 14 April 2011

Create a home VPN and allow computers to connect with each other

Like most organisations, my workplace has quite strict security policies. For some reason, I wasn't allowed and able to connect to the data centre through the Cisco VPN that had been set-up by our company. I had to had a static URL at home that needed to be allowed, but I wouldn't consider changing my provider purely for that benefit.

There are plenty of options to 'break' that security restriction, like having a Terminal Server within your corporate network that you could log onto. The slow and clunkiness of that solution turned me off. In addition, I would have to get helpdesk to install all sorts of programmes and, since I'm a Linux man, I would have to compromise on every which way.

The easiest solution, I thought, was, since I can't VPN onto the network from home, to VPN to my home network from work!

I already have a server for various tools that keeps on running most days and nights, so why not also use it as a VPN server.

Installing and configuring the necessary software is easy and takes just minutes.
First you will need to install the PPTP daemon:
$ sudo apt-get install pptpd
In Ubuntu, the configuration file for the pptp-daemon is: /etc/pptpd.conf and we will need to modify it so there is a separate IP defined for a) the server (which can be the one the server is getting from your router) and b) the client(s). If you have more than one client you will obviously have to make sure you have a range of IPs available for the clients.

In my case, since the networks should be quite separate at home and through VPN, I decided to use a different IP range. My router assigns IPs in the range 192.168.1.XXX, so I will use the range 192.168.0.XXX through my VPN server. You will need to update the last lines of your pptpd.conf like this:

localip 192.168.0.1
remoteip 192.168.0.2-10
This assigns the IP ~.1 to the VPN server (a separate interface) and allows the numbers ~.2 to ~.10 to be assigned to clients.

Next step: create VPN users and their passwords. This is stored in the /etc/ppp/chap-secrets file. Here is an example:

# Secrets for authentication using CHAP
# client server secret IP addresses
CLIENTLOGIN pptpd CLIENTPASSWORD *
You could obviously restrict the IP addresses the client can connect, but a very long password should also be quite secure.
In theory that's all you need to connect, but you might want to allow clients to use the server's internet connection and allow it to connect to other IPs within your local network. For this we will need to use NAT and IP forwarding. You can enable this via adding this line to your /etc/rc.local (before exit):

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

and in /etc/sysctl.conf uncomment the line:
net.ipv4.ip_forward=1
Now you can restart the daemon:
$ sudo /etc/init.d/pptpd restart
If your computer doesn't use the public IP address, eg. you are behind a modem - router or a firewall, you will need to forward the port 1723 to your server. And to avoid trouble with dynamic IP addresses you get from your ISP, you should use a dynamic DNS service. This will update your current IP to the DNS lookup tables and you get an easy URL name to remember. I think I use DynDNS.org.

Finally, you are on the client, but you can't see any other computers within the VPN or the local network of the server. This is because the routing is not set correctly on your client computer. You will want to "search" this VPN IP range through the VPN server, not your normal internet connection, so you can add a manual route like this:
route add -net 192.168.0.0 netmask 255.255.255.0 dev ppp0
Tadah! You can find other computers in the VPN!

For more advanced routing, eg: make your client's local connections available to hosts local connections, I advise to take a look at this page full of knowledge. The beauty is that once the VPN connection is established, you can bridge pretty much all connections through using routing and iptables.


Gig Lovers

d3ngar @ Gig Lovers