2013-10-15

Sharepoint's full page little trick

For those of you with a very specific task to create a hotsite in sharepoint(MOSS) and can't (or dont want to) create a new template just for that, here it goes:
https://gist.github.com/tiagodll/6990155
with this simple snippet your div is the new body of your page so go ahead and put the whole html code you need in there.
Loading ....

2013-08-15

CSS Expandbox

Those of you following my posts for a while might know that I like javascript.
I like javascript as much as I like not using javascript when I can use css instead.

So trying to make an expandable box I realised its behaviour is very similar to a checkbox. you have the small excerpt and when you click it you get the full text.

That being said, it is possible not only to change the label properties according to its state, but to set its state by clicking the label.


<style>
  input[type="checkbox"].expand-content{ display:none; }

  input[type="checkbox"].expand-content + label .collapsed { display:block; }
  input[type="checkbox"].expand-content + label .expanded { display:none; }

  input[type="checkbox"].expand-content:checked + label .collapsed { display:none; }
  input[type="checkbox"].expand-content:checked + label .expanded { display:block; }
</style>

<input class="expand-content" id="theradio" type="checkbox" />
<label for="theradio">
    <div class="collapsed">
this is the small content</div>
<div class="expanded">
this is the big content</div>
</label>

This is also available on my gist profile

2013-07-13

How to fix any computer

Not the usual content of this blog, but this couldn't be more true...


2013-07-11

Elixir + MongoDB = SMART! Just like a chap...

 + 


What do you want to do every time you test a new programming language?

- connect to a db, obviously

But when you are using something as new as elixir (please note we don't even have a 1.0 yet) that can be some sort of challenge.
Also I came from Microsoft world, programming open source things in a mac is a whole new world to me
OK, not that new, it has been over 1 year now, but you have to realise I started programming VB in 1998 (god I feel old now!)

Anyway, back to it. You want to connect to a DB, but you don't have drivers for Elixir. 
What do you do, sit in the corner of the room and cry like a little girl?
No little grasshopper, keep in mind elixir run on erlang vm, you are in erlang's world now!

So, how do we do that?
we chop it into pieces - like our old chap Jack would say.

Part 0 - What you have to have before this

Start your mongodb (go to the folder and type sudo ./mongod)
Sounds obvious, but you would be amazed how often the obvious is forgotten.


Part 1 - Make sure you can connect to it

I like to always isolate the small bits to make sure they work separately, nothing better than using the iex for that.
download the driver
git clone https://github.com/mongodb/mongodb-erlang mongodb
go to the folder you just created and type 
make

now go to the ebin folder, open iex but add some extra parameters to add bson's ebin in the path as well

cd ebin
iex -pa ../deps/bson/ebin

now you are ready to start

:application.start(:bson)
:application.start(:mongodb)
{ :ok, conn } = :mongo_connection.start_link({:localhost, 27017}, [])
result = :mongo.do(:safe, :master, conn, :db, fn() -> :mongo.count(:test, []) end )

if everything went fine you should get the counting of documents you have in the collection test in the database db

great, now lets make it into an app!

Part 3 - Make it into an app

to create an app just type 
mix new /path/to/your/project

now edit your mix.exs to include the dependencies you have
This failed for me every time I added the git urls, so what I did was to clone them into the folder deps, make (just like above) and then added them in the mix.exs with the path :

  defp deps do
    [ {:bson, path: "deps/mongodb/deps/bson", override: true },
      { :mongodb, path: "deps/mongodb" } ]
  end

then all you have to do is to add the code to your app:

defmodule YourApp do
:application.start(:bson)
:application.start(:mongodb)

{ :ok, conn } = :mongo_connection.start_link({:localhost, 27017}, [])
result = :mongo.do(:safe, :master, conn, :db, fn() -> :mongo.count(:test, []) end )
IO.puts "You have #{result} documents in your collection"
end

go back to shell, run
mix deps.get
mix deps
to make sure they're all ok
mix run



Don't be sad if your result is 0, that just means you don't have any documents.
you can add them with:
:mongo.do(:safe, :master, conn, :db, fn() -> :mongo.insert(:test, [{:id, 1, :title, "test", :body, "testing post"}]) end )    

that is it, now you have an app that can access mongodb

Lets just go over some details to keep in mind:

when using erlang libs in elixir, so you can go in the original library help (in this case http://api.mongodb.org/erlang/mongodb/ )and use it with some little changes

mongo:do(safe, master, Conn, db, fun() -> mongo:insert(test, [ {id,1, title, "test" ]) end). 
becomes
:mongo.do(:safe, :master, conn, :db, fn() -> :mongo.insert(:test, [{:id, 1, :title, "test", :body, "testing post"}]) end )

  • erlang libs are atoms in elixir, and because of that you use :mongo
  • instead of : you use . to get functions
  • all the symbols should have : in front
  • variables doesn't have to start with capital letters
  • fn() instead of fun()
  • you have to use double quotes for strings. single quotes means array of integers
  • no . in the end


but that is it

coming up next: make this a web app

See you lads, 
have a good one!



Notes:
  • Special thanks to José Valim and Alexei Sholik who helped me to make this mongodb driver work
  • For those who didn't get the reference in the title... check Mr.B The Gentleman Rhymer

2013-06-23

So, what is elixir?



A bit of background first:
In my masters I had a module called Programming Paradigms and Languages.
What this module is about is the different paradigms, and one language for each of them.

The chosen languages were:
Object Oriented: Ruby
Functional: Clojure
Logical: Prolog
Process Oriented: Erlang
Mathematical Programming: Matlab

Out of that what I can say is:

  • Ruby syntax is awesome. So elegant but there are many performance issues
  • Clojure is very nice for the academic world, but I cant imagine anyone using it for commercial software building.
  • Prolog. Ah, prolog... I have had a love/hate relationship with this since my undergrad. Powerful but very specific.
  • Erlang: blazing fast. handle processes like no one else, but it is probably the worst syntax I've ever seen. Ok, not the worst, but close to that (Yes mind fuck, I didn't forget you)
  • Matlab... this doesn't even had to be in this list


So, after that my conclusion is: I want a language able to handle many processes like erlang, but with a nice syntax like ruby and maybe add there some cool recursion features from clojure if you can.

That is elixir.

"Elixir is a functional meta-programming aware language built on top of the Erlang VM. It is a dynamic language with flexible syntax with macros support that leverages Erlang's abilities to build concurrent, distributed, fault-tolerant applications with hot code upgrades."- http://elixir-lang.org/

So, just like that it has become my favorite language.
But just like all open source, making it work is always a hassle. But this is for the next post.

Lets have an easy start: how to add Elixir to your path?
I am new to the mac world, for those of you that like me are not great at this, let's go step by step:
  1. check if it is already there: type "echo $PATH" on bash (capital letters)
  2. if elixir is there, you are good to go. if it is not, add it by typing
    echo 'PATH=$PATH:/Software/elixir/bin' >> ~/.bash_profile (I put it in the folder Software under root, use your path)
  3. close your bash and open it again. type iex, if you get the interactive shell, go ahead and play with it :)