Getting Laravel to use the Bootstrap 4 Alpha

I’m developing a Markdown-based notes taking platform with Laravel, and I want it to use all the latest and greatest CSS framework: the Boostrap 4 Alpha. To get this set up, I had to learn how web applications and Laravel maintains dependancies and packages code. The default site that Laravel generates has some links on the default page, and if you add the built-in authentication with PHP Artisan, those pages are served with an older version of Bootstrap. So how do you change this?

First, you need to add Bootstrap 4 Alpha as a dependency in the NPM dependency file “package.json” like, as well as Laravel’s version of Gulp called “Elixir” and it’s version of “Webpack”, another JS tool, like so:

"laravel-elixir": "^3.0.0",
"bootstrap-v4-dev": "^4.0.0-alpha.6",
"laravel-elixir-webpack": "^1.0.1"

You should then run NPM’s install to get the latest files. Now, navigate to the SCSS file in your Resources/Assets/SASS directory from your root Laravel directory. In app.scss, remove any unneeded lines, and make it look like this:

@import "node_modules/bootstrap-v4-dev/scss/bootstrap.scss";

This imports the new version of Bootstrap instead of whatever version your project came with. When we run Gulp, this will compile the latest Bootstrap SCSS files for your Laravel application, but we’ll also need to update the JavaScript file. Navigation to the Bootstrap JS file in Resources/Assets/JS, and make replace any mention of the Bootstrap JS (probably “bootstrap-sass”) file with this line:

require('bootstrap-v4-dev');

With your dependancies installed and your assets pointing towards Bootrap 4, it’s time to set up Gulp so that you can compile these into your web application. Create a “gulpfile.js” in your root directory and add these lines:

var elixir = require('laravel-elixir');
var elixir = require('laravel-elixir');
require("laravel-elixir-webpack");

elixir(function(mix) {
   mix.sass('app.scss').webpack('app.js');
});

Now, when you run “gulp” in your root directory, you should find that your CSS and JavaScript have been updated to Bootstrap 4.

How I picked Laravel Homestead as my first backend development platform

As an experienced iOS developer, I interface all the time with backend services, and JSON RESTful APIs in particular. It’s a fairly common story for iOS developers to begrudge their work being blocked by backend holdups or bugs, and so, I thought I might as well try to try my hand at backend development to see if I could fix these problems myself.

Working on Apple platforms is simple. Language? Swift. OS? MacOS. IDE? Xcode. On and on, many questions have one answer. So you can imagine my uneasiness when asking the same questions on my first steps into backend development. Language? Uh, Ruby or PHP or Javascript or Java or … OS? Well, you can develop on whatever you want and you can run software on whatever you want, but probably something UNIXIDE? Well, what OS did you pick? And what language? And why aren’t you using Vim you filthy casual? (Emacs get out.)

Okay. I had some choices to make. I’ve heard from a few sources that backend should be old, boring, and crucially, reliable. I could think of no better candidate than PHP, and given that a few of the projects I’ve worked on have successfully deployed with PHP and I have some previous experience with it, it seemed like a reasonable first choice.

But I don’t want to fall into the trap of writing bad code, which I understand is easy to do in PHP, and I also don’t want to write code that has been written better by people that came before me. So I did some digging for PHP frameworks, and I found Symphony, CodeIgniter, and Laravel. The way that I picked one of these was the very scientific approach of picking the one with the most starts on GitHub, for better or worse, which at time of writing is Laravel.

I now set out to get a development environment up and running for Laravel, and to do that, here’s what you do. You’ll need to download Vagrant, which is a manager for virtual machines, VirtualBox, which is a virtualization engine, and Homestead, which is a nicely configured Laravel virtual machine. Homestead uses Vagrant which runs on VirtualBox.

To get this up and running, I found these tutorials very useful:

It took a while, but I now have it working, and I’m ready to start developing my Laravel app.

Display an HTML encoded String in a UITextView without changing characters to emoji

I wanted to display some text in a UITextView, and one of the glyphs was a Unicode checkmark, which I didn’t think anything of. But what I was finding was that when iOS rendered the checkmark, it was an emoji version instead of the boring old Unicode variant.

Before I ran into that issue though, I had to solve how to turn an encoded HTML string into something useable. A string like this:

<b>Hello</b><br><p>This is normal text.</p><br>

So I wrote an extension on attributed string to solve this problem, which uses some hackery to coax iOS into parsing and rendering the string for me:

extension NSAttributedString {
    convenience init?(htmlEncodedString: String) throws {
        if let data = htmlEncodedString.data(using: .unicode) {
            let rawHTML = try NSAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil).string
            let styledHTML = "\(rawHTML)"

            if let htmlData = styledHTML.data(using: .unicode) {
                try self.init(data: htmlData, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
            } else {
                return nil
            }
        } else {
            return nil
        }
    }

It abuses the fact that NSAttributedString can take an NSData, which can understand HTML encoding, and then you can grab the decoded HTML string from it. At runtime, the raw HTML variable will look like:

<b>Hello</b><br><p>This is normal text.</p><br>

After that, NSAttributedString can understand this HTML and turn it into something you can render for the user. The weirdness comes when you include Unicode characters like the following:

✉✔✌✍❤☀☂☯☢☎❄▶◀

I cannot guarantee that these are rendering the same on your machine, particularly if iOS has the same behavior in browser. For sake of precision, these values in encoded Unicode are supposed to be:

0x2709, 0x2714, 0x270C, 0x270D, 0x2764, 0x2600, 0x2602, 0x262F, 0x2622, 0x260E, 0x2744

But these were rendering in the UITextView as all emoji!? I found that solution was to use this scantily documented “Unicode variance selector” by suffixing the   violating Unicode values with it. Granted, I do not know if this is a definitive list of the Unicode values which do this on iOS, but I’ve wrapped all this up in an extension which you can use for your own purposes:

extension String {
    var escapingCharactersWithVariationSelector0E: String {
        var newStr = ""
        for unicodeScalar in unicodeScalars {
            switch unicodeScalar.value {
            case 0x2709, 0x2714, 0x270C, 0x270D, 0x2764, 0x2600, 0x2602, 0x262F, 0x2622, 0x260E, 0x2744:
                var escapedScalar = String(Character(unicodeScalar))
                escapedScalar.append("\u{0000FE0E}")
                newStr.append(escapedScalar)
            default:
                newStr.append(Character(unicodeScalar))
            }
        }

        return newStr
    }
}

To wrap this all up, if you’d like to display:

var str = "&lt;b&gt;Hello&lt;/b&gt;&lt;br&gt;&lt;p&gt;This is normal text.&lt;/p&gt;&lt;br&gt; ✉✔✌✍❤☀☂☯☢☎❄▶◀"

You can use:

do {
    textView.attributedText = try NSAttributedString(htmlEncodedString: str.escapingCharactersWithVariationSelector0E)
} catch {
    ()
}

Please share the other Unicode values that do this! And check out the attached Playground which demonstrates the effect.

StringPlayground.playground

Apple’s education share and Google’s Chromebook

Natasha Singer via Michael Tsai:

The public school system in Eudora, Kan., for instance, used to have rolling carts of iPads for elementary school classrooms and MacBook carts for older students to share. But last year, when administrators wanted to provide a laptop for each high school student, the district bought 500 Chromebooks at about $230 each.

[…]

To compete with Chromebooks, Microsoft announced last month that it had worked with Acer, HP and Lenovo to develop low-cost Windows laptops for schools, with prices starting at $189.

This is sounding like a familiar refrain, but it seems like either Apple doesn’t care about this market or it completely misjudged its needs. I haven’t used a Chromebook, but at least on paper it seems like a near perfect machine for education: great price and durability, a real keyboard, a larger screen than on Apple’s cheaper devices, cloud-based productivity apps, and little need for administration. In some cases, students would need the full power of a Mac or PC, but for most education uses they don’t.

As a user of the candy-colored Macs in school and a developer on Apple platforms, it saddens me to hear Apple’s performance in this market. Education and design have been Apple bastions for a decade, I wish the relationship would continue. This is especially interesting in light of Apple’s new ad campaign for iPad Pro, going with the line that it gets “no PC viruses.” Google have been addressing that market need in another way, Chromebooks have the advantage of coming pre-installed with spyware!

Planet of the Apps

I was skeptical about Apple’s first reality TV show, but after watching the trailer, “Planet of the Apps” seems better than I thought it would be. It’s definitely reality TV, so I won’t watch it, but it seems more toned down than it typically is.

WWDC in San Jose

Here’s Dan Moren on the latest news on WWDC:

Well…didn’t see that one coming. Apple’s announced that the 2017 incarnation of its Worldwide Developers Conference will be held from June 5 through June 9, but not in its usual home at the Moscone Center in San Francisco. Instead, the event will take place at the McEnery Convention Center in San Jose, about an hour south of the city.

I seem to recall Tim Cook saying something to the effect of, “see ya next year in the spaceship!” I wonder if things got delayed and bridges were burned at Moscone West, leading to this decision. Given the proximity to Campus 2, I wonder if any events will take place there.

The state of iBooks

Michael Cohen at TidBits, via 512 Pixels:

I cannot see into the heart of Apple to judge the depth of its love for iBooks, but, from external appearances, whatever affection it has seems to become ever more shallow with each passing release. And, for an ebook lover like me, that is heartbreaking.

iBooks is not without its problems, though I find it vastly superior to the Amazon Kindle app and I find it generally quite reliable for reading ebooks. The number of free books on the iBooks store is also appreciated.

Highlights from Theresa May’s address to Congressional Republicans

Theresa May’s address to Congressional Republicans:

“We must never cease”, Churchill said, “to proclaim in fearless tones the great principles of freedom and the rights of man which are the joint inheritance of the English-speaking world and which through Magna Carta, the Bill of Rights, the Habeas Corpus, trial by jury, and the English common law, find their most famous expression in the American Declaration of Independence”.

So it is my honour and my privilege to stand before you today in this great city of Philadelphia to proclaim them again, to join hands as we pick up that mantle of leadership once more, to renew our Special Relationship and to recommit ourselves to the responsibility of leadership in the modern world.

And it is my honour and privilege to do so at this time, as dawn breaks on a new era of American renewal.

For I speak to you not just as Prime Minister of the United Kingdom, but as a fellow Conservative who believes in the same principles that underpin the agenda of your Party. The value of liberty. The dignity of work. The principles of nationhood, family, economic prudence, patriotism – and putting power in the hands of the people.

[…]

New enemies of the West and our values – in particular in the form of Radical Islamists – have emerged.

And countries with little tradition of democracy, liberty and human rights – notably China and Russia – have grown more assertive in world affairs.

The rise of the Asian economies – China yes, but democratic allies like India too – is hugely welcome. Billions are being lifted out of poverty and new markets for our industries are opening up.

But these events – coming as they have at the same time as the financial crisis and its fall out, as well as a loss of confidence in the West following 9/11, the military interventions in Iraq and Afghanistan, and sporadic terrorist attacks – have led many to fear that, in this century, we will experience the eclipse of the West.

But there is nothing inevitable about that. Other countries may grow stronger. Big, populous countries may grow richer. And as they do so, they may start to embrace more fully our values of democracy and liberty.

But even if they do not, our interests will remain. Our values will endure. And the need to defend them and project them will be as important as ever.

So we – our two countries together – have a joint responsibility to lead. Because when others step up as we step back, it is bad for America, for Britain and the world.

It is in our interests – those of Britain and America together – to stand strong together to defend our values, our interests and the very ideas in which we believe.

[…]

Because of these strong economic and commercial links – and our shared history and the strength of our relationship – I look forward to pursuing talks with the new Administration about a new UK/US Free Trade Agreement in the coming months. It will take detailed work, but we welcome your openness to those discussions and hope we can make progress so that the new, Global Britain that emerges after Brexit is even better equipped to take its place confidently in the world.

Such an agreement would see us taking that next step in the special relationship that exists between us. Cementing and affirming one of the greatest forces for progress this world has ever known.

AP: “Equipment Didn’t Detect North Dakota Oil Leak”

The Associated Press via ABC:

Electronic monitoring equipment failed to detect a pipeline rupture that spewed more than 176,000 gallons of crude oil into a North Dakota creek, the pipeline’s operator said Monday.

It’s not yet clear why the monitoring equipment didn’t detect the leak, Wendy Owen, a spokeswoman for Casper, Wyoming-based True Cos., which operates the Belle Fourche Pipeline, said.

A landowner discovered the spill near Belfield on Dec. 5, according to Bill Suess, an environmental scientist with the North Dakota Health Department.

I can’t tell if this is unbelievable or completely believable, but either way this is terrible.

United Airlines will charge for overhead bins

Ben Brooks:

United has a new ticket fare, where no luggage is included in the price (except what fits at your feet). If you want overhead bin space, or to check, you pay. I actually love this, though I would much rather checked luggage be free and overhead charged for everyone.

I have no doubt this scheme is at least partly motivated by a desire for increased revenue on the side of the airlines, but I’m pleased that people will now be forced to more deliberate in the size and location of their bags when flying – a couple of times I’ve had pieces of luggage damaged by people cramming in overheads.

Shared interests of the populist right and the progressive left

Jeremy Corbyn via the BBC on the relationship between the progressive left and populist right:

“They are political parasites feeding on people’s concerns and worsening conditions, blaming the most vulnerable for society’s ills instead of offering a way for taking back real control of our lives from the elites who serve their own interests.

“But unless progressive parties and movements break with a failed economic and political establishment, it is the siren voices of the populist far right who will fill that gap.”

The Labour leader said economic conditions had been exploited by the populist right.

“We know the gap between rich and poor is widening; we know living standards are stagnating or falling and insecurity is growing; we know that many people rightly feel left behind by the forces unleashed by globalisation, powerless in the face of deregulated corporate power,” he said.

Bernie Sanders via CBS This Morning:

“We will hold Mr. Trump accountable. We have all of the things he has said and we are going to say to Mr. Trump, if you have the courage to actually stand up to the big money and trust of the billionaire class, if you have the courage, in fact, to develop policies to improve lives for working people count us in,” Sanders said. “You want for increase the infrastructure and way equity for women, we are on your side.”
Two different countries, politicians, and messages, but same cautious view of the populist right.

 

WSJ: “China’s Dalian Wanda Group Faces Renewed U.S. Regulatory Scrutiny”

The Wall Street Journal reports of Chuck Schumer, New York Senator and House Minority Leader:

Mr. Schumer said the ability for Chinese companies to take a majority stake in U.S. assets, often backed by state officials and China’s sovereign-wealth funds, is unfair considering stateside companies are handicapped from doing similar deals in China. U.S. companies hoping to do business in China usually have to form a joint venture that often includes the sharing of intellectual property—an arrangement that Mr. Schumer called a “pay to play system.”

I was critical of the decision to go with Schumer as minority leader, but if he continues to take action like this, I would gladly retract that.

Send as text message in iOS 10

Michael Tsai:

I found several forum posts, but the only solution seems to be to temporarily turn off iMessage, which seems like a terrible solution because it means that you won’t be able to receive iMessages from anyone else in the interim. Worse, the iMessages will look to the sender like they got delivered because they’ll still go to your Mac or iPad.

Ideally, there would be a way to simply start a new conversation using SMS even though there is an iMessage account associated with that phone number.

I absolutely agree. A text message is preferred when reception is spotty, and this whole thing gets very confusing when your talking to someone who has an iMessage account separate from their phone number and a phone number with SMS.

Mike Pence went to see Hamilton

From the New York Times:

As the play ended, the actor who played Aaron Burr, Brandon Victor Dixon, acknowledged that Mr. Pence was in the audience, thanked him for attending and added, “We hope you will hear us out.”

I don’t support this – Mike Pence is a paying customer to a see a play, and he should be treated by the establishment as equally as possible. Even if the message is fairly innocuous, I don’t think this was a classy move to do without Mike Pence’s approval. However, with regards to:

When Mr. Pence entered the Richard Rodgers Theater in Manhattan, he was greeted with a mix of clapping and booing, according to theatergoers who posted on Twitter.

While I don’t support this treatment of the vice-president elect, I think this is a fair expression of the theater-goers First Amendment rights – if Mike Pence is free to express his anti-gay beliefs, which he is and he should be, he also must face the public, especially metropolitan, opposition to these views.

Donald Trump and the Paris Accord

Donald Trump has appeared to or has been characterized as pulling back on his promises to “build a wall”, “drain the swamp”, “lock her up”, and more. But if there’s any campaign promise I want him to pull back on, it’s not implementing the Paris Accord. From Democracy Now!:

As Democracy Now! broadcasts from the U.N. climate talks in Marrakech, Morocco, we report that nearly 200 nations have agreed on a proclamation that declares implementation of the Paris climate accord to be an “urgent duty.” This comes just over a week after the election of Donald Trump, who has vowed to pull the United states out of the Paris Agreement and has called climate change a Chinese-created hoax. Meanwhile, climate activists staged protests targeting corporate sponsors of the climate talks.

Even if there were a plausible case for skepticism in man-made global climate change, the gamble of potentially making large swaths of land uninhabitable and unarable is not worth the risk.

iPhones send call history to Apple if you’ve enabled iCloud

The Intercept reported via a digital forensics firm that iPhones with iCloud enabled send user’s call history to Apple servers:

Russian digital forensics firm Elcomsoft has found that Apple’s mobile devices automatically send a user’s call history to the company’s servers if iCloud is enabled — but the data gets uploaded in many instances without user choice or notification.

“You only need to have iCloud itself enabled” for the data to be sent, said Vladimir Katalov, CEO of Elcomsoft.

This can be justified. Apple do a number of things with your phone call: they allow you to answer calls on any of your devices, they allow third parties to make VoIP calls that look and feel like normal phone calls, for instance. Apple’s response:

“We offer call history syncing as a convenience to our customers so that they can return calls from any of their devices,” an Apple spokesperson said in an email. “Device data is encrypted with a user’s passcode, and access to iCloud data including backups requires the user’s Apple ID and password. Apple recommends all customers select strong passwords and use two-factor authentication.”

It is still technically accessible to law enforcement via a subpoena, but granted, I believe this is true anyway given that carriers would happily provide call logs too. The mistake Apple made here is not in the actual behavior of the phone, but in the disclosure to users. This should have been made clear to the user, or at least found in their famously long agreements.

ProPublica exposes professors being hired by corporations to justify their mergers.

The most straightforward example of corporate purchase of academic economic research in their favor that ProPublica found was Dennis Carlton:

Dennis Carlton, a self-effacing economist at the University of Chicago’s Booth School of Business and one of Compass Lexecon’s experts on the AT&T-Time Warner merger, charges at least $1,350 an hour. In his career, he has made about $100 million, including equity stakes and non-compete payments, ProPublica estimates. Carlton has written reports or testified in favor of dozens of mergers, including those between AT&T-SBC Communications and Comcast-Time Warner, and three airline deals: United-Continental, Southwest-Airtran, and American-US Airways.

This is the elitism that is the source of America’s growing populism, with academic class gorging themselves on corporate-funded and government subsidized hit-peice publications that justify decisions that benefit that same academic, political, banker, and corporate class. The politicians making the most noise about this are hugely popular: Bernie Sanders, Elizabeth Warren, Ron Paul, and Donald Trump come immediately to mind. ProPublica continue:

In addition, politicians such as U.S. Senator Elizabeth Warren have criticized big mergers for giving a handful of companies too much clout. President-elect Trump said in October that his administration would not approve the AT&T-Time Warner merger “because it’s too much concentration of power in the hands of too few.”

The merge has the same affect as trade deals: while it’s true that a broad view of the economy shows that there’s more capital in the system, it disproportionally benefits the rich and punishes the poor. Democrats and Republicans alike have been increasingly cozy with ex-corporate interest “independent” lobbyists which later become politicians themselves before getting hired by a corporation again. Obama in 2008 had a populist message, and moving to 2016 he’s become everything people didn’t vote for: bigger trade deals and bigger mergers and acquisitions:

A late Obama administration push to scrutinize major deals notwithstanding, the government over the past several decades has pulled back on merger enforcement.

The rest of the article explores how Apple’s iBooks price fixing scandal and the AT&T/Time Warner deal are examples of being technically advantageous to the United States on grounds that while the customers face a bigger burden, the corporation can take advantage of efficiencies to deliver more value to shareholders. And if this difference is net positive, they argue, it is a good merger. But this is false because empowering the people at the base of the economy with competition for cost and features is better for more people and has broader positive economic effects. When consumers have more money, they can afford more, take a chance at starting a business, have a kid, and many more positive outcomes. But when a very narrow group of executives, politicians, and academics funnel more money into their accounts by taking advantage of efficiencies in economics of scale, they’re actually delivering capital to where it is least needed. ProPublica conclude:

Today, AT&T’s much grander takeover of Time Warner will be an early test case for president-elect Trump, who feuded during the campaign with CNN, a Time Warner property.

If Trump blocks the deal, I hope it’s the first in a series of good decisions; if he allows the deal, he’ll have completely repudiated his claim that he’ll “drain the swamp.” Ideally, the populist liberals and conservatives in all the branches of government can unify to fight this establishment corporatism.

Facebook promises its users more censorship

Facebook via TechCrunch:

We take misinformation on Facebook very seriously. We value authentic communication, and hear consistently from those who use Facebook that they prefer not to see misinformation. In Newsfeed we use various signals based on community feedback to determine which posts are likely to contain inaccurate information, and reduce their distribution. In Trending we look at a variety of signals to help make sure the topics being shown are reflective of real-world events, and take additional steps to prevent false or misleading content from appearing. Despite these efforts we understand there’s so much more we need to do, and that is why it’s important that we keep improving our ability to detect misinformation. We’re committed to continuing to work on this issue and improve the experiences on our platform.

It’s amazing how straightfacedly and unironically this VP admits to and endorses censorship, as though they have some unique access to the truth, like the solution to Trump getting elected is even more media control. But to their point, it’s their platform, and they can control the flow of information all they want, to me it’s another reason not to use Facebook.