Saturday, February 18, 2012

tDCS -- say what?

WARNING:
You should NOT experiment with tDCS WITHOUT MEDICAL SUPERVISION, experiments with tDCS were and are made on perfectly healthy people, therefore if you have any health issues whatsoever(even allergies), please consider only informing yourself about this subject and NEVER, under any circumstances, try to experiment.

Yesterday I've found out about tDCS -- no, it's not a Delphi class, but there should be one! -- while reading this article on gizmodo.com

Short Q&A:
Q: what does the name mean?
A: the longer version of the name is Transcranial Direct Current Stimulation


Q: is it dangerous?
A: let's put it this way: if you don't read enough about it(both pros and cons) and you're not ready to take the risk of going loco, then, maybe you shouldn't hook a battery to your head.


Q: applications?
A: some can be read here, here, here, here and of course google

In case you haven't checked the article on gizmodo, here's an image illustrating the idea behind it(courtasy of gizmodo.com)

The trouble with us currently, is that we don't have enough time these days to learn something new, tDCS could be a cheat that we can activate whenever we need, but we can't run around with a battery in our pocket or remember to charge it every day, because it can take some time to get used to and it can get pretty odd, so how can we cheat(yet again)?
It turns out that for quite a few years, there's a little device in our pocket or near us every day that we take special care of being charged, that's right! your mobile phone/tablet/laptop! but what do this three types of devices have in common? well, most of them have a mini usb, so with two wires hooked to your brain and plugged into your favorite device's usb port, tadam! you got yourself a tDCS on the go.

For the purpose of this article, I will choose an Android phone as a good device for experimenting, why? because it is very flexible, you can do a lot of weird stuff with it, after all, it is using a linux kernel...

The Cocktail:
- one rooted(it may be possible to play with it without rooting, not sure) Android phone
- an app that let's you fiddle with the usb
- a mini usb cable
now that you have everything you need, I assume that the app is capable of managing the amount of current the usb port will serve and that you have thought about this long enough, you can start experimenting!

Here are a couple of ideas:
- X second(s) on, X second(s) off
- X second(s) on, Y second(s) off
- take the rhythm of your favorite song, translate it into electrical impulses
- test your skills on something that puts your brain to work, first without tDCS and then with, but on different   games/tests/etc.
- test all or part of the above using an EEG(i.e. http://emotiv.com/, too expensive? then take a look at this) device
once you've started, I'm sure you can take experiments to a whole new level, next level, next level! (:

Since Free Pascal is capable of creating Android apps, maybe you should start there?

I would love to read your ideas regarding this project.

Was Ray Kurzweil right about singularity being near? I believe so, what do you think?


Sometime within the next couple of days, I'll post something that is partially related to this, but much more significant in terms of applications and lower health risk.

Monday, May 9, 2011

Boyer-Moore Horspool return all occurrences in one go

First I would like to say that I'm sorry for not posting for quite some time now, but thanks to Simon H. who found a bug in original algorithm found here, I've managed to also extend the function to return all occurrences of a pattern in a string, without further introduction here's the code!
type
  TFSResults = array of Integer;

function FindStringMulti(const Value, Pattern: string;
  const CaseSensitive: Boolean = True;
  const StartPos: Integer = 1): TFSResults;
var
  Index: Integer;
  jIndex: Integer;
  kIndex: Integer;
  LLenPattern: Integer;
  LLenValue: Integer;
  LSkipTable: array[Char] of Integer;
  LChar: Char;

    function __SameChar: Boolean;
    begin
      if CaseSensitive then
        Result := (Value[Index] = Pattern[jIndex])
      else
        Result := (CompareText(Value[Index], Pattern[jIndex]) = 0);
    end; // function __SameChar: Boolean;

begin
  LLenPattern := Length(Pattern);
  if LLenPattern = 0 then
    Exit;
  for LChar := Low(Char) to High(Char) do
    LSkipTable[LChar] := LLenPattern;
  if CaseSensitive then begin
    for kIndex := 1 to LLenPattern -1 do
      LSkipTable[Pattern[kIndex]] := LLenPattern -kIndex;
  end else begin
    for kIndex := 1 to LLenPattern -1 do
      LSkipTable[Windows.CharLower(@Pattern[kIndex])^] := LLenPattern -kIndex;
  end; // if CaseSensitive then begin
  kIndex := LLenPattern + (StartPos -1);
  LLenValue := Length(Value);
  while (kIndex <= LLenValue) do begin
    Index := kIndex;
    jIndex := LLenPattern;
    while (jIndex >= 1) do begin
      if __SameChar then begin
        jIndex := jIndex -1;
        Index := Index -1;
      end else
        jIndex := -1;
      if jIndex = 0 then begin
        SetLength(Result, Length(Result) +1);
        Result[High(Result)] := Index +1;
        jIndex := -1;
      end; // if jIndex = 0 then begin
      kIndex := kIndex + LSkipTable[Value[kIndex]];
    end; // while (jIndex >= 1) do begin
  end; // while (kIndex <= LLenValue) do begin
end;

Enjoy!

Blogroll(General programming and Delphi feeds)