Monthly Archives: January 2014

Discussions Gone – Google Search

It looks like Google has removed the discussions search filter for some browsers (currently using Chrome Version 32.0.1700.76 m).

Hoping this is a bug and not another part of the “simplicity” trend they’re on at the moment.

Solution #1: Append &tbm paramter to url
A temporary fix is to add “&tbm=dsc” to the end of the search url. SilentEcho has added this script to automate it if you’re going to be using it a fair bit: http://userscripts.org/scripts/reviews/293082

Solution #2: Change Use Agent String
You can also use a user agent string of a browser that it still works for (I’ve heard Opera but haven’t verified).

Solution #3: Sign Out of Google Account
This didn’t work for me, however quite a few people are saying it does the job for them.

Thanks to this thread for the links/info: http://productforums.google.com/forum/#!msg/websearch/Psb6OmlLJTg/NoW2hr-qytcJ

Random Class Directive – AngularJS

Hey everyone,

Just another small directive. This one adds a random class from the provided array to the element.

Check out this fiddle to see the demo: http://jsfiddle.net/uvSVj/3/

Random Background Directive

Random Background Directive

I used this directive to add a random background to each of my wrapper divs:

Random Background Real World Usage

To use it in your app simply define a list of classes in your controller:

app.controller("MyCtrl", function MyCtrl($scope) {
 
    /* A random class is picked from this list */
    $scope.classes = [
        //"bg-buildings",
        "red",
        "blue",
        "yellow",
        "green",
        "orange",
        "black",
        "purple"
    ];        
});

Then add the directive to your page (can be an existing element):

<div class="test" ng-random-class ng-classes="classes"></div>

A random class will then be selected from the list and appended to the elements current list of classes (if any).

The easiest way to see how it’s done is probably just to check out the fiddle above, but there’s a code dump below if you need it:

The Random Class Directive

app.directive("ngRandomClass", function () {
    return {
        restrict: 'EA',
        replace: false,
        scope: {
            ngClasses: "="
        },
        link: function (scope, elem, attr) {            
 
            //Add random background class to selected element
            elem.addClass(scope.ngClasses[Math.floor(Math.random() * (scope.ngClasses.length))]);
        }
    }
});

Sample Html

<div ng-app="myApp">
    <!--Shameless link back to blog -->
    <h1>Random Class Directive</h1>
    <a href='http://www.whatibroke.com/?p=899'>www.whatibroke.com</a>
 
    <!-- Identical divs with random class directive added -->
    <div ng-controller="MyCtrl">
        <div class="test" ng-random-class ng-classes="classes">
        </div>
        <div class="test" ng-random-class ng-classes="classes">
        </div>
        <div class="test" ng-random-class ng-classes="classes">
        </div>
        <div class="test" ng-random-class ng-classes="classes">
        </div>
        <div class="test" ng-random-class ng-classes="classes">
        </div>
        <div class="test" ng-random-class ng-classes="classes">
        </div>
        <div class="test" ng-random-class ng-classes="classes">
        </div>
        <div class="test" ng-random-class ng-classes="classes">
        </div>
        <div class="test" ng-random-class ng-classes="classes">
        </div>
        <div class="test" ng-random-class ng-classes="classes">
        </div>
        <div class="test" ng-random-class ng-classes="classes">
        </div>
        <div class="test" ng-random-class ng-classes="classes">
        </div>
        <div class="test" ng-random-class ng-classes="classes">
        </div>
        <div class="test" ng-random-class ng-classes="classes">
        </div>
        <div class="test" ng-random-class ng-classes="classes">
        </div>
    </div>
</div>

Sample JS

/* 
    http://www.whatibroke.com/?p=899
    Adds a random class to element
    Usage: add ng-random-class to element
*/
 
var app = angular.module('myApp', []);
 
app.controller("MyCtrl", function MyCtrl($scope) {
 
    /* A random class is picked from this list */
    $scope.classes = [
        //"bg-buildings",
        "red",
        "blue",
        "yellow",
        "green",
        "orange",
        "black",
        "purple"
    ];        
});

Sample Styles

/* Just a demo div */
.test{
    width: 50px;
    height: 50px;
    margin: 10px;
    padding: 5px;
    float: left;   
    -webkit-transition: 400ms linear all;
	-moz-transition: 400ms linear all;
	-ms-transition: 400ms linear all;
	-o-transition: 400ms linear all;
	transition: 400ms linear all;
    cursor: pointer;
    border-radius: 10px;    
}
 
.test:hover{
    opacity: 0.8;    
}
 
body{
	background-color: #F0F0F0;
	font-family: "Lato", sans-serif;
	font-weight: 300;
	color: #363636;
    text-align: center;
    vertical-align: middle;
}
 
/* Random classes */
.red {
    background-color: red !important;
    height: 75px;
    width: 75px;
}
 
.blue {
    background-color: blue !important;
    height: 40px;
    width: 40px;
}
 
.yellow {
    background-color: yellow !important;
    height: 20px;
    width: 20px;
}
 
.green {
    background-color: green !important;
    height: 63px;
    width: 63px;
}
.purple {
    background-color: purple !important;
    height: 82px;
    width: 82px;
}
.black {
    background-color: black !important;
    height: 29px;
    width: 29px;
}
.orange {
    background-color: orange !important;
    width: 42px;
    height: 42px;
}

Let me know if you run into any issues and feel free to use/change however you want.

EF Generated Migrations Not Including New Model – Empty Up/Down

Hey everyone,

A quick issue I ran into today, my generated migrations weren’t detecting any of the models I’d added – only changes to existing models. Unfortunately the solution was so obvious that it didn’t even come up on Google.

I had forgotten to add the table to the DBContext file… Once this was done it all worked fine.

Working IPN Handler with Parallel Payments – PayPal Adaptive Payments

Hey everyone,

Just a dummy implementation of a Parallel Payment and an accompanying IPN Handler using the C#/.NET SDK. Feel free to use it however you like.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//Handles PayPal IPN
        public String IPN()
        {
            //Post back to either sandbox or live
            string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            //string strLive = "https://www.paypal.com/cgi-bin/webscr";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
 
            ////Set values for the request back
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            byte[] param = Request.BinaryRead(Request.ContentLength);
            string strRequest = Encoding.ASCII.GetString(param);
            strRequest += "&cmd=_notify-validate";
            req.ContentLength = strRequest.Length;
 
            //Send the request to PayPal and get the response
            StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            streamOut.Write(strRequest);
            streamOut.Close();
            StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
            string strResponse = streamIn.ReadToEnd();
            streamIn.Close();
 
            if (strResponse == "VERIFIED")
            {
                //check the payment_status is Completed
                //check that txn_id has not been previously processed
                //check that receiver_email is your Primary PayPal email
                //check that payment_amount/payment_currency are correct
                //process payment
            }
            else if (strResponse == "INVALID")
            {
                //log for manual investigation
            }
            else
            {
                //log response/ipn data for manual investigation
            }
 
 
            return "";
        }
 
        //Pay for an order
        public void Pay(int OrderId)
        {
            RequestEnvelope envelopeRequest = new RequestEnvelope();
            envelopeRequest.errorLanguage = "en_US";
            PaySample paySample = new PaySample();
 
            List<Receiver> listReceiver = new List<Receiver>();
            // Amount to be credited to the receiver's account
            Receiver receiverA = new Receiver(Convert.ToDecimal("4.00"));
 
            // A receiver's email address
            receiverA.email = "test_buyer1@learnerlessons.com.au";
            listReceiver.Add(receiverA);
 
            // Amount to be credited to the receiver's account
            Receiver receiverB = new Receiver(Convert.ToDecimal("2.00"));
 
            // A receiver's email address
            receiverB.email = "test_buyer2@learnerlessons.com.au";
            listReceiver.Add(receiverB);
 
            ReceiverList receiverList = new ReceiverList(listReceiver);
 
            PayRequest requestPay = new PayRequest(envelopeRequest, "PAY", "http://localhost:53034/orders/cancel", "AUD", receiverList, "http://localhost:53034/orders/return");
            requestPay.reverseAllParallelPaymentsOnError = true;
            requestPay.ipnNotificationUrl = "http://123.123.123.123/Orders/IPN";
 
            //Send request to paypal, retrieve payKey
            PayResponse payResponse = paySample.PayAPIOperations(requestPay);
 
            Response.Redirect("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey=" + payResponse.payKey);
        }

Configuring Custom Settings – PayPal C# SDK

Hey everyone,

I’ve been mucking around with the C# SDK for PayPal Adaptive Payments. Unfortunately the docs aren’t too great and the samples are a little confusing until you get your head around them.

One of the main issues I’ve had is working out how to configure payment request settings i.e. reverseAllparallelPaymentsOnError.

To do this, simple utilise the PayRequest class:

1
2
PayRequest requestPay = new PayRequest(envelopeRequest, "PAY", "http://localhost:53034/orders/cancel", "AUD", receiverList, "http://localhost:53034/orders/return");
requestPay.reverseAllParallelPaymentsOnError = true;