Category Archives: Uncategorized

Bootstrap Carousel Tutorial: getting started, then customizing — example code & bugs

Recently I had “great fun” modifying bootstrap v3’s image gallery slideshow thingy, Carousel (click here to see an interactive example).

It has some nice features built-in, like indicators for what slide you are on, auto-scaling so it works on any browser window size, and an easy way to select options like cycling the carousel continuously, changing the interval between auto-slides, or reacting to keyboard events.

I made some modifications to get it to look and behave the way I wanted. Namely, I wanted readable captions underneath the images. Bootstrap has the captions overlaid on the image by default, and white-on-white doesn’t work so well.

I mostly succeeded… here’s a screenshot:

Screenshot from 2015-01-21 15:36:57
Live at doc.arvados.org someday soon…

…although I still dislike how verbose the Carousel code is. Oh well, our docs site was already using Bootstrap.

The how-to on bootstrap’s page is pretty terse and kind of confusing for me, so I’m writing up a more detailed explanation here.

stuff needed

From http://getbootstrap.com/getting-started/, download the zip file. You’ll need

1. css/bootstrap.css (you can use the .min version if you’d like, which is just compressed into non-human-readable form)

2. js/bootstrap.js (you can also get away with just carousel.js).

You’ll also need jquery.js from http://jquery.com/download/, try the link “Download the compressed, production jQuery 1.11.2”.

Note: We’ll include the javascript files at the end of HTML so most of the page loads quicker.

how to

Alright, now how do you include all these files? (see this gist for the full HTML file, or download a self-contained zip file of all the files: bootstrap-carousel-example).

Put the CSS at the top, either by linking to a .css file or including the CSS directly:

<head>
  <link href="./css/bootstrap.css" rel="stylesheet">
  <style>
    /* put your custom CSS here if you'd like, for instance... */
    .carousel { 
      margin: 1em; 
    }
  </style>

Inside the body section, put your Carousel HTML.  It’s kind of long so just check out the gist. Put the javascript at the bottom, either by linking to a .js file or else including it directly

<script src="./js/jquery.min.js"></script>
<script src="./js/bootstrap.min.js"></script>
<script type="text/javascript">
// Put your custom javascript options here, for instance...
$(document).ready(function() {
    $('.carousel').carousel({interval: 100});
    });
</script>
</body>

</html>

step 3: profit?

If you load the html file in your browser, magic should now happen.

For reference, you can download this zip file where everything is set-up already: bootstrap-carousel-example

step 4: customize

What if we want the images to cycle faster, or the images to not cycle at all?

Okay, I’ve already shown how you can select some of the built-in bootstrap options using javascript:

$(document).ready(function() {
    $('.carousel').carousel({interval: 100});
    });

You can select individual carousels on a page by naming the carousel

<div id="carousel-keyfeatures" class="carousel slide" data-interval="false">

and then using a more specific jquery call

$(document).ready(function() {
    $('.carousel-keyfeatures').carousel({interval: 100});
    });

Alternatively, if you want some option to apply to all carousels on a page / site, you can pull this code out into a separate file

./js/carousel-override.js

and include it in each HTML file

<script src="./js/carousel-override.js"></script>

A third way to change an the options on a carousel is to include it in the HTML, like so:

<div id="carousel-example-generic" class="carousel slide" data-ride="carousel" data-interval="false">

step 5: sweeter customizations!

Now, to make more custom modifications, I had to fiddle with the CSS. A few hours later, I made the modifications you can see at this gist. Alternatively, download the zip file and uncomment the line

<link href="./css/carousel-override.css" rel="stylesheet">

trouble-shooting tips (bugs!)

First, cool tools:

1) Use firefox or chrome’s powerful built-in developer tools. The default shortcut to bring them up is ctrl-shift-c (you actually can’t get rid of our change this shortcut easily, which is annoying).

You can delete things, edit things without refreshing the page or modifying files, and other wonderful tools.

Screenshot from 2015-01-21 16:44:34
Screenshot of Firefox’s “Inspector” tool in use.

2) Use a Javascript hint tool, such as http://jshint.com/.

If you just use the Console tool in Firefox Inspector to see the javascript error messages, it is fairly cryptic.

SyntaxError: missing ) after argument list

Tools like JSHint can provide some more helpful feedback about what went wrong.

bugs

these things tripped me up:

1) the Bootstrap website makes ( and { look very similar on my computer, so I skipped the curly brackets and used

$('.carousel').carousel( interval: 2000 )

instead of the correct

$('.carousel').carousel({ interval: 2000 })

UPDATE 03 April 2015

I filed a bug on github: https://github.com/twbs/bootstrap/issues/16225, or as follows:

Font in code blocks on http://getbootstrap.com/ does not distinguish { and ( clearly, can cause anguish for newcomers to javascript. Please remove the Courier New font fallback option. Just monospace works well.

In Detail

I was following the the example at http://getbootstrap.com/javascript/#carousel, and my brain removed the “extra parenthesis” I think, similar to how you don’t notice I doubled “the” in this sentence unless I point it out.

This is a screenshot of the bootstrap website “code” block font currently on my computer:
js-bootstrap-font

Please remove the courier new font fallback option. Just monospace works well.

 code, kbd, pre, samp {
   font-family: monospace;
 }

Results in the much-better

js-bootstrap-font-better

(Most open-source projects in have nice websites but no issue tracker nor contact info for their own website or their documentation, only for their github repo around the actual code, and it’s not always clear where to file a bug…)

END UPDATE

2) I didn’t realize I needed to include the jquery file first, so I got cryptic messages like “$ is undefined”.

3) I spent a while debugging a weird gap that left the rightmost controls in midair. It occurred when the browser window was too big. Turns out I needed to hardcode a max-width, which I just hardcoded to be slightly smaller than the smallest image width I had.

appendix

Here are the files used in this tutorial again:

Gist

bootstrap-carousel-example.zip

2014: robots, sea kayaking/sailing/backpacking, alternative living, bioinformatics

mmm, nyancake!
mmm, nyancake!

…or something. I’m ignoring facebook’s attempt to summarize my life for the moment.

In review, I’d say it was a good year: lots of adventures, first time experiences, new friends. There were some ups and some downs. The downs are still intensely personal, so I apologize for not sharing them right now and only showing the highlight reel of my life.

alright, now that I’ve established this is a pretentious and obnoxious post meant for myself,

Firsts

first wedding attended, for my awesome friend-since-elementary-school, Alice

20140913_172940

 

first full-time job, with the awesome Curoverse

20141010_112152
sneakermail genomes!

first time cosplaying and sewing my own costume (holy FRICK that was a lot of work)

20140322_015701
lie ren
boston anime convention 2014
boston anime convention 2014

outdoors

  • sea kayaking out to an island and camping on it

20140615_084402

20140615_003510

  • winter hiking

20140201_141102

  • backpacking
20140520_114134
ponies!

20140520_114025

20140521_141100

  • bluewater sailing
first sighting of Boston while travelling north from Fairhaven
first sighting of Boston while travelling north from Fairhaven
night-time botoring (boat motoring), view of Boston
night-time botoring (boat motoring), view of Boston

robots

  • manufacturing and shipping robots (yes, we delivered our kickstarter on-time!) and teaching a class to close to 100 people
b7e89ff3656f06740838ecbf689ed628_large
final parts count before we seal and ship our robot kits
e89aa8f745748d37dfa3b73276656857_large
engineering notebook drawings from a student
02657e6993e2c51bcee89841b95b6f75_large
that student’s final project
    • making sweet point-and-click camera-controlled robots (with help from our wonderful interns), albeit they failed on kickstarter, they were still cool from a technical standpoint

dark-staffpick

 

(sorry about my face at the beginning, it’s cropped from a longer video)

alternative living

  • liveaboard
20140830_211154
my home for a few weeks
IMG_20140604_133856
what it looks like out of the water
  • tiny home
20140929_083155
we started with the bare trailer and installed radiant heating and insulation
plywood siding going up
plywood siding going up
tarpaper to weatherproof our structure
tarpaper to weatherproof our structure

Thankful

I find myself being thankful a lot.

Wallet stolen in Mexico? Well, I’m still happy, healthy, and well-educated so I can go home and make more money. Sick with a cold? Well, at least it’s an infrequent occurrence and I’m not living in constant pain like sufferers of lupus or lyme disease.  And I’m not in danger of losing my job, which is understanding of sick days.

It’s almost like my brain is on obnoxiously optimistic mode. Ah well, I’ll enjoy it while it lasts.

Upsides

the upsides of having been through something traumatic in my childhood (and also travelling extensively) and also having been suicidal:

I grew up thinking most people had something or other they were intensely passionate about. But many of my current friends seem adrift, uncertain what they care about or what they are qualified to do anything about. Perhaps there is nothing wrong with being adrift and open to different directions, but (due to societal expectations?) they often seem to be in a state of malaise.

My trauma forged me: it tore me down, but I survived it and am stronger for it. These childhood experiences give me a sense of purpose in life, an acute and visceral sense of the injustice in and sheer incomprehensibility of our lives.

Thinking about death daily for an extended period of time also puts a different perspective on things, for better or for worse. I’m very happy with my life at the moment, but thanks to my experiences with wishing to die, I feel a focus on making the most of my life and defining what matters to me. For whatever reason, the house with a picket fence and a dog, something easily within my grasp if I worked for it thanks to the advantages I live with, has no appeal to me. Similarly, my focus is not on finding a relationship, nor on hitting the next “milestones” in the conventional path of life (university, career, husband, children, retirement, death), but rather on finding my life.

This past year, I thought my point of living was to have adventures and explore the breadth of sensation and possible experiences in life — things I cannot experience once I am dead. I’m not sure what the theme of this upcoming year will be, but I suppose a year of relative stability (moving three times in six months sucks!) might not hurt.

things i’d like to accomplish in 2015:

  • publish a paper
  • figure out what I want to accomplish in ten years and analyze the things I should try to get there

crap (stuff) i liked

“However, I continue to try and I continue, indefatigably, to reach out. There’s no way I can single-handily save the world or, perhaps, even make a perceptible difference- but how ashamed I would be to let a day pass without making one more effort”.

-Isaac Asimov,  “The Relativity of Wrong”

(src)

“For me, I am driven by two main philosophies: know more today about the world than I knew yesterday and lessen the suffering of others. You’d be surprised how far that gets you.”

– Neil deGrasse Tyson

and one from pop culture

Every night I used to pray that I’d find my people, and finally I did on the open road.
We had nothing to lose, nothing to gain, nothing we desired anymore, except to make our lives into a work of art.

– Lana Del Rey, “Ride”

(src) (related 5 minute TED talk: A glimpse of life on the road)

For instance, on the planet Earth, man had always assumed that he was more intelligent than dolphins because he had achieved so much — the wheel, New York, wars and so on — whilst all the dolphins had ever done was muck about in the water having a good time. But conversely, the dolphins had always believed that they were far more intelligent than man — for precisely the same reasons.

-Douglas Adams

Curoverse Internship

Recently I started work at Curoverse, which I like to describe as “the cloud for genomes,” and I like to describe my job as “being paid to work on open-source bioinformatics software.”

I think the official site has some more informative words to say on this subject and talks about the vision of enabling biomedical information sharing to improve research and clinical outcomes or something.  Anyway, I’m an intern so thankfully I haven’t had to pitch the idea repeatedly every day until I can present it in a concise and powerful manner 🙂

I’ve been having a great time. I mean, it’s (a) open-source (b) bioinformatics (c) python (d) has nothing at all to do with cruel cruel robots.  😛

I’ve learned a lot about genomes, sequencing, and all the pitfalls of genomes, aka why Arvados (the open-source platform Curoverse is working on) is needed:

20141010_112152

That is fifty phased genomes, shipped on multi-terabyte hard drives to us. Sneakermaillll!

Here are some important things I have learned during the month or so I’ve been at the job so far:

1) Our mascot is called Dax. It is adorableeeeee

mascot

No, we don’t have plushies of Dax yet, but soon!

Oh! I could easily revolve this and make a 3d model that I could print off this weekend. Hmm. *adds to todo list*

2) In software, open-source is much more established and can be seen as a boon by customers, especially by researchers and clinical or governmental infrastructure.

3) Having a stable source of income is great! Having really knowledgeable co-workers is great! Having an office with an ergonomic chair and free tea is great! Plus, all my work is open-source, so I can easily refer to it in the future, or point people / my friends at it.

4) It’s been super interesting to see the sales and development cycle. I’ve been observing Curoverse’s strategies for finding the so-called “product-market fit” and the continual effort to find and work on what customers want — in some senses, selling something before developing it.

Okay, I’m sort of just rambling here, so I’ll talk a little bit about the environment I’ve found myself in and the work I’ve been doing.

1) Environment:

The location is great. It’s a few minutes walk from the South Station stop on the Red Line, and within walking distance to Chinatown as well as views of the water.

20141016_104342

It’s all open-style desks, no cubicles. Everyone’s right next to each other, and furthermore EVERYONE IS ON IRC. (even some of our customers apparently!). It works surprisingly well, since I’ve had cases where I’ll ask someone a question (in the team chat) and someone else will give me a faster way to do it / enable me to do it myself. It’s still not zephyr with its classes that let you sort through a multi-threaded conversation easily, but it’s nice.

Unlike what I’ve come to expect of software development, a lot of the folks are older / married / have kids, and also have more engineering experience of course. There’s also a GPL ninja floating around…

What really puzzled me at first was calling one section of software developers “engineering” and another “science,” but it makes sense now. I just expected the engineering team to be building more robots I guess. ^^;

The engineering team operates on “agile” development (or lean?) — anyway the main thing to me is they are always talking about stories, which amuses me. I imagine them typing away drafting a really epic novel sometimes.

The science team, which I have found myself on, has standups every day as well, were we all stand up and present to the rest of the team what we’ve been up to.  Standing up hasn’t seemed very effective at keeping our standup short though o_o

Every Friday there is also free lunch err I mean, a company meeting, which keeps everyone on the same page.

Oh! I got to attend the first Curoverse social.

20141014_193155

Delicious pizza (flatbread) and bowling! It was candlepin bowling, where the pins are flattened like candlesticks instead of like the traditional bowling pin and the balls are solid and a bit bigger than a softball.

20141014_212927

(yep, people are wearing their work outfits, which vary a lot).

2) What I’ve been working on.

Right away I got involved in working with GA4GH, aka the Global Alliance for Genomics and Health, or more accurately working on projects the GA4GH groups determine are important. I made a little python+flask webapp and learned how to serve it using uWSGI and nginx,as well as learned a bit of working with postgresql (such as the fact that DISTINCTs take a significant chunk of time, aka seconds, because they query across the whole table!).

Screenshot from 2014-10-16 15:04:30

I’ve also been playing around with javascript to make POSTs to an API and return the results.

Screenshot from 2014-10-16 15:04:26

OH! AND WRITING TERRIBLE BASH SCRIPTS because apparently bioinformaticians not only can’t agree on whether to 0-index or 1-index, but also make these convoluted file formats followed by convoluted file-format-conversion tools that require specifically named files in certain directories all documented in a PDF somewhere on the internet. WHYYYY

Screenshot from 2014-10-16 15:08:26

Hmm, well, now I feel like I haven’t done much since I can sum it all up in three images. Regardless, I sure have learned a lot while getting paid to do so, and I’ve always had plenty of work to do. There’s in fact a GA4GH conference this weekend where my supervisor might demo some of my work as part of the science team’s work, which is nifty.

See you all next time!