[ This is a content summary only. Visit our website http://ift.tt/1b4YgHQ for full links, other content, and more! ]
by Irfan Ahmad via Digital Information World
"Mr Branding" is a blog based on RSS for everything related to website branding and website design, it collects its posts from many sites in order to facilitate the updating to the latest technology.
To suggest any source, please contact me: Taha.baba@consultant.com
Wouldn't it be nice to have a way to make more money without working 60 hours a week? Or to have something to offer to people whose budget is too low for your services right now, but who really like your style?
If you're willing to put in a little extra effort up front, information products can be a huge help when it comes to both of these issues--and they can go a long way when it comes to evening out the ups and downs of freelance income.
First off, for the sake of this article, an info product means something like an instructional ebook or a "how to" video--as opposed to a software product. Obviously, building software requires a lot more work than creating a user guide. An info product takes less time for you to create but still provides value for your customers.
Continue reading %How to Earn Passive Income by Creating Digital Info Products%
Previously, we saw how to configure a Laravel app to handle Braintree subscriptions.
This time, we'll talk about how to:
As it stands, if we visit the plans index page, we can still see the Choose Plan button for the plan we are currently subscribed to, and this shouldn't be the case. In the plans index view. let's add an if conditional to hide the button based on the user's subscription status:
[...]
@if (!Auth::user()->subscribedToPlan($plan->braintree_plan, 'main'))
<a href="" class="btn btn-default pull-right">Choose Plan</a>
@endif
[...]
But that's not to say users can't access the plan by typing in the URL pointing to the same plan in the address bar. To counter this, let's update the code in the show action of the PlansController to this:
[...]
public function show(Request $request, Plan $plan)
{
if ($request->user()->subscribedToPlan($plan->braintree_plan, 'main')) {
return redirect('home')->with('error', 'Unauthorised operation');
}
return view('plans.show')->with(['plan' => $plan]);
}
[...]
Here, we are getting the user from the request object; remember all our routes fall under the auth middleware and thus it's possible to get the authenticated user. Once we get the user, we check if they are already subscribed to the plan. If that's the case, we redirect them to the homepage and display a notification. We will implement basic flash messaging later.
One last precaution is preventing users from submitting the payment form with a different plan ID value. It's possible to inspect the DOM element and change the value for the hidden input. In our SubscriptionsController, let's update the store method to this:
[...]
public function store(Request $request)
{
$plan = Plan::findOrFail($request->plan);
if ($request->user()->subscribedToPlan($plan->braintree_plan, 'main')) {
return redirect('home')->with('error', 'Unauthorised operation');
}
$request->user()->newSubscription('main', $plan->braintree_plan)->create($request->payment_method_nonce);
// redirect to home after a successful subscription
return redirect('home')->with('success', 'Subscribed to '.$plan->braintree_plan.' successfully');
}
[...]
Let's now implement some basic flash messaging to display notifications in the app in response certain operations. In the resources/views/layouts/app.blade.php file, let's insert this block right above our content since flash messages show up at the top before any other content:
Continue reading %Laravel and Braintree: Middleware and Other Advanced Concepts%
Elixir is built on Erlang, and in both Erlang and Elixir a function is not just identified by its name, but by its name and arity. Remember: Everything in Elixir is an expression.
To give you a clear example of this, below we have four functions, but all defined with different arity.
def sum, do: 0 def sum(a), do: a def sum(a, b), do: a + b def sum(a, b, c), do: a + b + c
To provide a concise way to work with data, we can use guard expressions like so:
def sum(a, b) when is_integer(a) and is_integer(b) do a + b end def sum(a, b) when is_list(a) and is_list(b) do a ++ b end def sum(a, b) when is_binary(a) and is_binary(b) do a <> b end sum 1, 2 #=> 3 sum [1], [2] #=> [1, 2] sum "a", "b" #=> "ab"
Guard expressions such as when is_binary(a) allow us to check for the correct type before performing an operation.
Unlike Erlang, Elixir allows for default values in its functions via usage of the \\ syntax like so:
def mul_by(x, n \\ 2) do x * n end mul_by 4, 3 #=> 12 mul_by 4 #=> 8
In the previous part, we discussed anonymous functions briefly as a data type. To elaborate on this further, take this example:
sum = fn(a, b) -> a + b end sum.(4, 3) #=> 7 square = fn(x) -> x * x end Enum.map [1, 2, 3, 4], square #=> [1, 4, 9, 16]
We see this powerful shorthand here on the first line fn(a, b) -> a + b end. With this we are able to produce a basic operation sum.(4, 3) and get the output in just two lines of code.
Now, looking to the square method, fn(x) -> x * x end, can it really be any simpler? Working now with the map, we can perform the square anonymous function over the whole map—again in just two lines of code!
Arithmetic is all fun and good, but let's see what we can do with text.
f = fn
{:simon} = tuple ->
IO.puts "Good morning Sir #{inspect tuple}"
{:kate} = tuple ->
IO.puts "Lovely day #{inspect tuple}"
[] ->
"Empty"
end
f.([])
#=> "Empty"
f.({:simon})
#=> "Good morning Sir {:simon}"
f.({:kate})
#=> "Lovely day {:kate}"
Here, with pattern matching we can define several outcomes in our control flow, again in hardly any code. Elixir's syntax is rapid to work with and mightily powerful, as we will see in the next example.
The anonymous functions we just covered are first-class values. This means that they can be passed as arguments to other functions and also can serve as a return value themselves. There is a special syntax to work with named functions in the same way:
defmodule Math do
def square(x) do
x * x
end
end
Enum.map [1, 2, 3], &Math.square/1
#=> [1, 4, 9]
Here we define a Math module with defmodule and define the square function. Then we can use this in conjunction with the map method demonstrated earlier and the Math module we just defined. We use the same operator &, allowing us to pass our function Math.square/1 to capture the square function's output for each entry in our list.
That's a whole lot of power for just one line. This is referred to as a partial function capture in Elixir.
We use the constructs if and case to control flow in Elixir. Like everything in Elixir, if and case are expressions.
For pattern matching, we use case:
case {x, y} do
{:a, :b} -> :ok
{:b, :c} -> :good
other -> other
end
And for comparison logic, we use if:
test_fun = fn(x) ->
cond do
x > 10 ->
:greater_than_ten
x < 10 and x > 0 ->
:less_than_ten_positive
x < 0 or x === 0 ->
:zero_or_negative
true ->
:exactly_ten
end
end
test_fun.(44)
#=> :greater_than_ten
test_fun.(0)
#=> :zero_or_negative
test_fun.(10)
#=> :exactly_ten
For ease of use, Elixir also provides an if function that resembles many other languages and is useful when you need to check if one clause is true or false:
if x > 10 do :greater_than_ten else :not_greater_than_ten end
This is possible in Elixir via usage of the unquote method mentioned earlier. For example, to check some hard-coded Admins in our system, we can do the following:
defmodule Admins do
[:manager, :super] |> Enum.each fn level ->
def unquote(:"check_#{level}")() do
IO.inspect("Access Level: #{unquote(level)}")
end
end
end
Admins.check_manager # => "Access Level: manager"
Admins.check_super # => "Access Level: super"
Here we have created the methods Admins.check_manager and Admins.check_super from the atom names.
Everything is an expression in Elixir, and that means we can get a whole heap of power out of writing very little code.
For me, Elixir looks similar to CoffeeScript, Ruby, Python or any minimalist syntax as the form is so direct and to the point, but Elixir is far more powerful than these languages due to the meta-programming aspect.
Going forward, we will see how to utilise control flow and functions more to create interactivity in our app.
The following is an extract from our book, Scrum: Novice to Ninja, written by M. David Green. Copies are sold in stores worldwide, or you can buy it in ebook form here. At the end of the sprint, everything that was worked on for the current sprint is demonstrated for the team, the product owner, […]
Continue reading %Scrum Rituals: Sprint Demo%
getlorem is a library for generating passages of Lorem Ipsum text, suitable for use as placeholder text in documents. This library can also be used as a jQuery plugin.