Saturday, May 16, 2020

Using Sinatra in Ruby - Introduction

In the previous article in this series of articles, we talked about what Sinatra is. In this article, well look at some real functional Sinatra code, touching on a few Sinatra features, all of which will be explored in depth in upcoming articles in this series. Before you get started, youll have to go ahead and install Sinatra. Installing Sinatra is as easy as any other gem. Sinatra does have a few dependencies, but nothing major and you shouldnt have any problems installing it on any platform. $ gem install sinatra Hello, World! The Sinatra Hello world application is shockingly simple. Not including the require lines, shebang and whitespace, its just three lines. This is not just some small part of your application, like a controller in a Rails application, this is the entire thing. Another thing you may notice is that you didnt need to run anything like the Rails generator to generate an application. Just paste the following code into a new Ruby file and youre done. #!/usr/bin/env rubyrequire rubygemsrequire sinatraget / doHello, world!end Of course this isnt a very useful program, its just Hello world, but even more useful applications in Sinatra arent much larger. So, how do you run this tiny Web application? Some kind of complex script/server command? Nope, just run the file. Its just a Ruby program, run it! inatra$ ./hello.rb Sinatra/0.9.4 has taken the stage on 4567 for development with backup from Mongrel Not very exciting yet. Its started the server and bound to port 4567, so go ahead and point your Web browser to http://localhost:4567/. Theres your Hello world message. Web applications have never been so easy in Ruby before. Using Parameters So lets look at something a little more interesting. Lets make an application that greets you by name. To do this, well need to use a parameter. Parameters in Sinatra are like everything else--simple and straightforward. #!/usr/bin/env rubyrequire rubygemsrequire sinatraget /hello/:name doHello #{params[:name]}!end Once youve made this change, youll need to restart the Sinatra application. Kill it with Ctrl-C and run it again. (Theres a way around this, but well look at that in a future article.) Now, the parameters are straightforward. Weve made an action called /hello/:name. This syntax is imitating what the URLs will look like, so go to http://localhost:4567/hello/Your Name to see it in action. The /hello portion matches that portion of the URL from the reqest you made, and :name will absorb any other text you give it and put it in the params hash under the key :name. Parameters are just that easy. There is of course much more you can do with these, including regexp-based parameters, but this is all youll need in almost every case. Adding HTML Finally, lets spiff this application up with a little bit of HTML. Sinatra will return whatever it gets from your URL handler to the web browser. So far, weve just been returning a string of text, but we can add some HTML in there with no problem. Well use ERB here, just like is used in Rails. There are other (arguably better) options, but this is perhaps the most familiar, as it comes with Ruby, and will do fine here. First, Sinatra will render a view called layout if one exists. This layout view should have a yield statement. This yield statement will capture the output of the specific view being rendered. This allows you to create layouts very simply. Finally, we have a hello view, which generates the actual hello message. This is the view that was rendered using the erb :hello method call. Youll notice that there are no seperate view files. There can be, but for such a small application, its best to keep all the code in a single file. Though the views are sepeated at the end of the file. #!/usr/bin/env rubyrequire rubygemsrequire sinatraget /hello/:name doname params[:name]erb :helloend__END__ layouthtmlbody% yield %/body/html helloh3Hello % name %!/h3 And there you have it. We have a complete, functional hello world application in about 15 lines of code including the views. The following articles, well take a closer look at the routes, how you can store and retrieve data, and how to do better views with HAML.

Wednesday, May 6, 2020

Presentation of Marlene, Top Girls in Comparison to the...

The main themes in both Top Girls and The Handmaid’s Tale are feminism, politics and women’s role in society. Top Girls is based on social realism and political drama. Churchill once said â€Å"Playwrights don’t give answers, they ask questions†.[1] It could be said that Churchill is asking the audience to acknowledge how much a woman has to sacrifice in order to succeed in the stereotypically male dominant workplace. However, it could also be said that she could be asking the audience to acknowledge how career power is perceived as a male trait and therefore successful career women have to adopt male attitudes. The Handmaid’s Tale, however, is a dystopian novel. Ostensibly it is a critique of a patriarchal society or it could also be said to†¦show more content†¦Serena Joy’s character in ‘The Handmaids Tale’ is also a very strong woman and fights for what she believes in – being an anti-feminist – and uses her success to persuade others to believe in what she believes in. However, where Marlene’s character and her feminist views believe women do not need men and their place in society should be equal to men, Serena’s character’s anti feminist views encourage her to encourage others to return into a patriarchal society where a woman’s place is in the home caring for the children, completing household chores and tending to the husbands needs and maintains that the woman’s role is to say in the house. Marlene and Serena Joy are both often seen to be victims of their own success. By this it is meant that they sacrificed certain aspects of their lives in order to achieve in another. For Marlene, this meant her sacrificing her family and intimate relationships. The audience may be shocked that Marlene could be ruthless enough to give up the child she carried and brought into the world, because Churchill does not allow Marlene to demonstrate sentimentality in respect of Angie. Motherhood seems to be a commodity and it is not until near the end of the play in a conversation with her sister, it almost seems that Marlene regrets putting her child into her sister’s care. This is shown when she says, â€Å"you couldn’t have one so you took mine†. This could be interpreted that Marlene resents Joyce for sticking by Angie and

Tuesday, May 5, 2020

Trust No One free essay sample

My eyes opened wide as I jumped out of bed onto the gray, stained carpet. What the hell is happening? My dad’s shaky voice confused me; my head spun. I couldn’t make out what he was yelling to my mother, but he was concerned or scared. I really couldn’t tell. My clammy hands shook and struggled to open the door. As I yanked it open, the ebony hardwood floors in the hallway beneath my father’s heavy footsteps screeched. By instinct, I quickly found myself running behind him not knowing the end destination. He went out the back door. I followed. He ran past the side of the house. I was with him. He stopped in the backyard. I stopped too, giving him a dirty, confused look. â€Å"What just happened?!† No answer. It was dead silent except for my heavy breathing. The night sky was pitch black—almost like a never ending hole that my head was quickly spinning through. We will write a custom essay sample on Trust No One or any similar topic specifically for you Do Not WasteYour Time HIRE WRITER Only 13.90 / page What. The. Hell. Happened. â€Å"Dad! Why did we run out here?†, I shouted. His eyes, darker than night, stared at me. â€Å"Somebody was back here.† * * * The occurrence was almost forgotten; nearly a distant memory in my family’s minds.If the topic was brought up, which rarely happened, the conversation had no serious tone to it. My concerns drifted away, out of my head, once I was given assurance that it wasn’t a big deal. Others’ thoughts seemed to take similar action because, after a few weeks, neighbors and friends spoke of nothing remotely close to it. Everybody, including myself, overlooked the seriousness of the situation. Days, weeks, months went by with no return from the mysterious person in my backyard. Life for my family and I changed the slightest bit from the incident. It was a fluke, never to happen again. My optimistic mindset jarred reality and how in danger my family really was. * * * My mother tiptoed through the jungle of my sister’s dirty clothes. Picking each item up one by one, she was finally making a dent in getting the room clean. Hours later, my mother finished; an accomplishment that she would cherish for the week to come until the room was filthy again. She decided to take one more lap around to make sure she hadn’t missed something. As she looked on the ledge, something caught her eye. A camera. Surprised, my mother asked my sister, â€Å"Is this yours?† My sister shook her head. â€Å"What the heck?†, My mother shouted erratically. After a quick judgement, she lurched for the phone and dialed 911 as soon as her shaking hands got a hold of it. Dark ebony flooring squeaked beneath her as she sprinted into the nearest bedroom; the phone pressed against her right ear. No words could be heard from outside of the door as my family anticipated her return. The door soon flew open; she swiftly pulled my dad to the side, gave us a long, hard look, and ran for the back door with my dad trailing. They didn’t have to say where they were going because there was only one place they would go, the police station. * * * The concerns that had drifted out of my mind dove right back in. The confusion I faced for the foreseen future was immeasurable. My parents refused to tell me all of what happened, saying it wasn’t my business. Left in the dark, I was unaware of the situation unraveling. Even then I waited, patiently, for information regarding the camera. Time stood still as we all desperately wanted to get a call back from the police. But weeks went by with no call. Maybe they forgot about it. That’s dumb. The police wouldn’t forget, right? Right. The phone finally rang. My father happened to be the one who picked it up off of the counter. What seemed to be a reoccurring event, my parents told my sister to get ready and left soon after. My brother and I, puzzled, sat at home speculating what could be happening. Oblivious to the intent of that camera, we were shocked when my parents arrived at home. My sister’s life shattered in front of my innocent eyes as I stood in the doorway. No words were exchanged, but they didn’t need to be. I realized the camera wasn’t hers, thus changing her life for the worst. Her privacy that she held so near and dear to her heart was broken. Not by just anybody, though. Our neighbor, my dad’s best friend, had ruined my sister’s life. Because of this, she was too scared to sleep in her own bedroom. She couldn’t sleep anywhere, knowing that somebody could be watching at any time of the day. Her senior year, a time that’s supposed to be fun, was filled with fear, hatred, and skepticism. My sister’s attitude shifted from a vibrant, open-minded person to a more cautious and enclosed person. Not only did she change, but as a result, I also changed. I came to a realization that would be tough for anybody, let alone an ignorant fourteen-year-old. My sister’s life crumble to pieces right in front of me, and all from the action of one person. â€Å"Why would somebody hurt another person for their own benefit?†, Played on repeat throughout my head. An answer never arose, though. This led to my realization that the world is just not what it seemed to be as a child. It isn’t great. Everybody isn’t your friend. And last but not least, you can’t trust anybody. Looking back, this change in my mindset transitioned me from childhood into adulthood.