dennismonsewicz
DennisMonsewicz.com
19 posts
Ramblings of yet another developer
Don't wanna be here? Send us removal request.
dennismonsewicz · 10 years ago
Text
Using Backbone.Wreqr Events with Marionette.Behaviors
For the past month (month and a half), I have been vigorously learning Backbone/Marionette/RequireJS as I am wanting to pivot at my current job to become a front-end resource. 
This post is going to discuss how you can use Backbone.Wreqr events (eventer) mixed with your Marionette.Behaviors so that you can decouple your Marionette.ItemView from worrying about elements inside it's individual template(s).
I have published an example application here.
The main focus of the app involves clicking on a menu item and then using the input search box to filter the results on the page. Instead of writing the same method in each ItemView file, we fire an event on keyup that is listened for inside the main Behavior class to then filter the collection on the page.
If you look in the home/view.js file in the example app you will see this piece of code:
https://gist.github.com/dennismonsewicz/e4336d927fc4c2895ce0
This code will fire an event on every keyup action. So, how do you set up your behavior to listen for it?
https://gist.github.com/dennismonsewicz/e3c6c2c0cbd8dc2834cf
As you can see in the above code snippet, you just configure the behavior in your ItemView and thats it!
0 notes
dennismonsewicz · 10 years ago
Text
Inferiority Complex:
Ghoulish. Cancerous. Defeat. Vulnerability.
All of the words above, and many others, can only be described as to be a part of my life for many years (~8). 
Inferiority Complex (IC): we have all experienced the unrealistic feeling of inadequacy at some point. You meet that one person, who is much better at everything they do. You feel as though when you are around them their superior knowledge overshadows your ability to think, speak or mingle. 
For the longest time, I, for one, have shared the holy bond of holding an IC. In my profession (software developer), I have watched many people reach their breaking point, only to not be able to see past their muddied thoughts to reach greener pastures so that they may brush their boots off to fight another day. These very people, became discouraged, drowned out helpful words and pushed away those who wanted to help. 
Why? Because they [I], saw these mentors as people who knew much more than they [I] and were unwilling to cope with the teachings bestowed upon them. 
My IC stems from never really having a mentor to instill great confidence in myself. I always played catch up, always a step behind (or so it seemed). Even in my every day job (almost 8 years later), I feel as though I will be "found out" to be one who does not possess enough skills worthy enough to have a desk in the office of my current employer.
Part of my every day process at my job is to submit Pull Requests (PR) into our different software repos, so that other developers may gander on the feeble code I have written. This entire process is very daunting for someone like myself, with a very strong IC, for you see, the very thought of receiving an email with suggestions for code cleanup or suggestions on improvement only breeds ferocious anxiety in my mind.
Coping with these thoughts is not easy. Reading PR comments is sometimes a task one might describe as painful as receiving open heart surgery, without anesthesia.
So, how do I cope with my IC? How do I defeat my IC on a daily basis?
Easy. Confidence.
Fear is defeatable. Fear is curable. Fear is an emotion that can be suppressed and hidden. Confidence, is key (a little cliché).
I use the fear that my IC instills in me and turn it around to breed confidence in others around me so that we all can learn from one another. Passing on your knowledge to someone else is one of the best tools to learning.
Am I perfect? Hell no. Will I always hesitate before submitting a PR? Yep. But you can bet your bottom dollar, that I'm going to soak up as much as I can from those around me with more knowledge so that the next time someone asks me a question, I can put a smile on, and point them in the right direction.
1 note · View note
dennismonsewicz · 10 years ago
Text
Integration Tests in Python with before_requests and session management
I have been developing in Python for roughly 5 months now and have learned a lot, not just about Python but also better practices in programming in general. 
Recently, I have been working on a project that involves logging in a user using a single sign-on cookie. Theoretically it's as easy as 1) checking existence for said cookie; 2) unsigning the secured cookie; 3) if session doesn't exist, set session and continue; 4) If cookie fails checks, redirect user to log in. The issue (for me at least) was trying to figure out how to write an integration test that simply checked to make sure the right template was used in the flask end-point I was testing.
Here's the code
https://gist.github.com/dennismonsewicz/b8c6093da0a5682e05cd
https://gist.github.com/dennismonsewicz/5e02481f8b91df62f015
Happy hunting!
0 notes
dennismonsewicz · 11 years ago
Text
Working with Meteor JS and the bootstrap3-wysihtml5 meteorite package
Recently I have started working on a small Meteor JS application (https://github.com/dennismonsewicz/meteor-cms-bootstrap-3) which is going to be a small CMS that will power my personal website (at least the blogging aspect).
When working with Meteor there are a ton of great third party packages that you can plug and play with (thanks to Meteorite). One of them in particular that I was playing around with is the bootstrap3-wysiwyg package (https://atmospherejs.com/package/bootstrap3-wysihtml5).
I kept running into a problem where if I had content that already existed in the database, the wysiwyg editor wouldn't populate with the existing content.
This is how I fixed it:
https://gist.github.com/dennismonsewicz/da541aacb906df33dc75
https://gist.github.com/dennismonsewicz/09a802cf2390091f260a
I am using a couple of other 3rd party meteorite packages to aid in building out my edit form, but you get the gist.
0 notes
dennismonsewicz · 11 years ago
Text
Rails 4: Working with Strong Parameters with Dynamic Forms
My development path has finally brought me to the avenue of Rails 4 and Ruby 2.1. The land of turbolinks, strong parameters and swift binary coding...
Now that I have tried to be a little poetic, let me get to the point of this blog post.
I am working on a project that calls for a user to dynamically add items to a form (by clicking on an add more link). Everything works as expected (on the front end), but strong parameters certainly did not like this idea. Here is how I solved the issue(s) I was having.
CoffeeScript
https://gist.github.com/dennismonsewicz/11c8bf6941a4515ae3d8
Form
https://gist.github.com/dennismonsewicz/8d235ba1312cf67b0705
Controller
https://gist.github.com/dennismonsewicz/25415da342ce50adfe4a
Models
https://gist.github.com/dennismonsewicz/7f0af9c441b65ce703c6
The focal point of this post is more in the view and controller. If you will notice in the code example above, we are setting the child index of the nested attributes with the current time.
If you were to use the traditional way of accepting these attributes with strong params, Rails would kick out the line_items hash. To allow for a dynamic form submission with a nested form, you have to use whitelist the entire line_items_attributes hash because we are dynamically setting the child_index.
From the Rails documentation: "Imagine a scenario where you want to whitelist an attribute containing a hash with any keys..." Rails Guide: Strong Params
Happy Hunting!
0 notes
dennismonsewicz · 11 years ago
Text
Rails 3: Back to basics with attr_accessible
Recently I was working on a project that contained a few *security flaws* in allowing all columns for a particular model to be accessed via forms in the application.
To rectify the issue, we not only needed to have a better management of setting associations, but also fixing potential injection problems. 
What is attr_accessible? attr_accessible allows you to specify which attributes of a model can be altered via mass-assignment (update_attributes(attrs) or new(attrs))
Let's take a look at an example.
https://gist.github.com/dennismonsewicz/7bfa8e50f8d3e0ae8724
In the above example, the form is opened up to allowing the admin flag to be submitted. What if the user being created isn't supposed to be an admin? 
Let's look at an example fixing this mass-assignment security hole:
https://gist.github.com/dennismonsewicz/3eaa37978406d7974d7a
The above shows us having better control in the application of setting the admin flag instead of allowing it to be maliciously set via HTTP requests. This security flaw has forced the Rails community to develop (in Rails 4) a new way of mass assigning attributes using Strong Parameters
This exercise was beneficial to me and the team I work with to button up any other security holes the app may be vulnerable too. Hope this helps!
Happy hunting!
0 notes
dennismonsewicz · 11 years ago
Text
Devise: Fast User Switching using a custom Authentication Strategy
Recently, my company needed a way to allow for users with a certain Access Control to log in (or impersonate) another user.
To be able to keep up with the original user, checking to see if the original user has access to the given user they would like to impersonate and signing in the user for impersonation, we came up with the following strategy for Warden.
https://gist.github.com/dennismonsewicz/f97b52c46aa3d0a7e2f0
https://gist.github.com/dennismonsewicz/373d1f74d3c02078630a
https://gist.github.com/dennismonsewicz/8fc54e22519510c02b95
Happy hunting! Dennis
0 notes
dennismonsewicz · 11 years ago
Text
Felis: Lightweight API Wrapper for Emma.com APIs
A year ago I wrote two API wrappers for Emma (The email marketing company located in Nashville, TN). One was in PHP, the other, Ruby. 
https://github.com/myemma/EmmaRuby
I decided to rewrite it in a different light. Felis is a lightweight wrapper that offers 4 simple methods to easily build integration into any Ruby/Rails app.
Check out Felis here: https://github.com/dennismonsewicz/felis
Happy hunting! Dennis
0 notes
dennismonsewicz · 11 years ago
Text
Active Admin, Kaminari and Rails boot up
Active Admin is an extremely nice tool when you need to have a quick 'plug & play' CRUD to give to admins to help administer a website.
One of the problems I kept running into was that every time my Rails server booted up (locally, production, etc), was that Kaminari (Rails gem for pagination - used by Active Admin; https://github.com/amatsuda/kaminari) would run through each registered Active Admin model and would attempt to override any page scope (by default Kaminari uses the method name of page when referring to pagination with a model and its results).
The problem looks like this (check your rails log during bootup):
https://gist.github.com/dennismonsewicz/9beedaea835e4a687472
To fix this issue simply do the following:
https://gist.github.com/dennismonsewicz/173fbfe9d25d679134c7
Happy Hunting! Dennis
0 notes
dennismonsewicz · 11 years ago
Text
Power in the context &block
Let me preface this post by stating that I am fairly new to the world of TDD and everything it encompasses.
In learning how to write tests, what to test and making sure my tests are performing correctly, one thing that helps [me] as well as reading others tests is using the context block in Rspec.
Context blocks help keep you're tests clear and concise and when you are working in a big team, it helps to quickly identify what your specifically trying to test.
https://gist.github.com/dennismonsewicz/8eb18720528a0fa5c3b5
Happy testing!
0 notes
dennismonsewicz · 12 years ago
Text
Rails 3 and modifying the link_to helper
One of the most recent applications I have been working on is an OAuth/Subscription Management/Product Store/User Management app. So far things have been interesting with trying to get every other app to play nicely with the way the internal engineering team has had to modify the OAuth system, but so far so good.
Within this application, we use an identifier in the URL titled client_id (http://url.com/hello?client_id=FANCY_CLIENT_ID_HERE). Upon entering the site, the application takes the client_id and sets the id in a session variable that is used to switch on/off branding (depending on which product or client you came in through). 
One of the annoyances we kept running into, is having to add the client_id to all of our link_to methods. So, today, I came up with the following:
def link_to(*args, &block) args[1] = params[:client_id].present? ? "#{args[1]}?client_id=#{params[:client_id]}" : args[1] super end
You place the above method in your ApplicationHelper and Rails will know to pick it up from your application stack and not from the helpers available in the Rails Gem.
Happy Ruby'ing!
0 notes
dennismonsewicz · 12 years ago
Text
Working with Rails Flash Messages
Today, I kept running into a peculiar issue with Flash messages without a redirect inside of my Rails controllers.
When writing flash messages with redirects, you typically write something like this:
flash[:notice] = "Your fancy flash message here" redirect_to your_fancy_path_here
This is how you get around displaying flash messages when rendering inside of a controller:
flash.now[:notice] = "Your fancy flash message here" render :partial => 'path/to/partial'
Obviously, in your partial, you would display the flash message. By using the flash.now syntax, the message will only stay active with the rendering of the partial, and will not stay with the user if the user navigates to a secondary page.
Happy Coding!
2 notes · View notes
dennismonsewicz · 12 years ago
Text
Extending the Ruby Array Core
So recently I kept running into an issue where I kept writing code like so:
arr = ['hello', 'world'] if arr.count > 2 #do code else #do something else end
So, to keep with being DRY, I simply extended the Ruby Array Core doing the following:
class Array def more_than?(num) length > num end alias_method :mt?, :more_than? end
Hope this helps someone!
3 notes · View notes
dennismonsewicz · 12 years ago
Text
Adding include_blank while working with Rails select_tag
If you are working with Rails and are using the options_for_select tag and are needing to include a blank option... try this:
<%= select_tag "district", options_for_select(@districts.collect { |d| [d["name"], d["id"]] }.insert(0, ["Select Your District", 0])) %>
This will insert (at the first index of the array) a new key:value which in turn will create your "default" value.
1 note · View note
dennismonsewicz · 13 years ago
Text
Rails Seeds.rb and the infamous #delete_all method
In my Ruby on Rails experience, I have seen many ways to "seed" a database. Using the included seeds.rb file or using fixtures (or an alternative like Factory Girl). Recently I have been working on a small API to aid in some upcoming internal projects and with that I was needing to "seed" my database with dummy data to get the ball rolling.
In "seeding" a database (rake db:seed), you typically want to clear out the database table first (Model_name.delete_all) so that the data is fresh. Well, I got tired of having to write multiple delete_all statements in my seeds.rb file and thus, came up with the following.
Dir["#{Rails.root}/app/models/*.rb"].each do |file| File.basename(file, ".rb").capitalize.delete_all end
Hope this helps!
1 note · View note
dennismonsewicz · 13 years ago
Photo
Tumblr media
For all of you "IE Lovers" out there
0 notes
dennismonsewicz · 13 years ago
Text
Errors when installing Ruby 1.9.3 with RVM on Mac OS X Lion
In my almost two years of Ruby development, the best way to run Ruby optimally and to manage multiple Ruby versioned projects is to install RVM (Ruby Version Manager). RVM allows you to work on a project that was developed in the latest ruby version all the way down to Ruby 1.8.7.
When installing Ruby on a Mac using RVM on Mac OS X Lion, you may or may not run into a couple of errors (especially if you are installing Nginx, MySQL, PHP, etc using Homebrew). One thing I can encourage you to do BEFORE installing RVM is to make sure you have the latest version of XCode. If you not, you will continually run into issues. Well, recently, while trying to install Ruby via RVM, I kept running into the following error...
Error running ' ./configure --prefix=/Users/dennismonsewicz/.rvm/rubies/ruby-1.9.3-p0 --enable-shared --disable-install-doc --with-libyaml --with-opt-dir=/Users/dennismonsewicz/.rvm/usr ', please read /Users/dennismonsewicz/.rvm/log/ruby-1.9.3-p0/configure.log There has been an error while running configure. Halting the installation.
The above error is caused by issues with the latest XCode (Ironic, I know) and the GCC Compiler. So how do you fix this?
rvm install 1.9.3 --with-gcc=clang
From Stackoverflow.com here is the explanation:
You need a non-LLVM version of GCC, which is no longer included with XCode 4.2. 
So, I hope this helps with your programming achievements in Ruby.
0 notes