xonecas.io
2495
Xg

xonecas.github.com / commit 8c99fc1

added post, and funny stuff

xonecas2013-02-25 8c99fc161f4f22aa43350a37b00d88e1970b4c04 parent 3447bcb

6 files changed

_layouts/default.html+6−2
@@ -3,7 +3,6 @@
33 <head>
44 <title>Sean Caetano Martin</title>
55 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6- <link href="/css/bootstrap.light.min.css" rel="stylesheet">
76 <link href="/css/bootstrap-responsive.min.css" rel="stylesheet">
87 <link href="/css/pygments.css" rel="stylesheet">
98 <link href="/css/styles.css" rel="stylesheet">
@@ -13,7 +12,7 @@
1312 <div class="navbar-inner">
1413 <div class="container">
1514 <a class="brand custom-font" href="/">Sean Caetano Martin</a>
16- <ul class="nav">
15+ <ul class="nav nav-main">
1716 <li>
1817 <a href="/blog.html">Blog</a>
1918 </li>
@@ -21,6 +20,11 @@
2120 <a href="/work.html">Work</a>
2221 </li>
2322 </ul>
23+ <ul class="nav pull-right">
24+ <li>
25+ <a id="light-switch" href="#">Flip the lights</a>
26+ </li>
27+ </ul>
2428 </div>
2529 </div>
2630 </div>
_posts/2013-02-25-random-title-generator.markdown+40−0
@@ -0,0 +1,40 @@
1+---
2+layout: post
3+---
4+
5+Random title generator
6+----------------------
7+
8+Sunnyvale, Feb 24, 2013
9+
10+Titles are hard, giving something a name demands thinking about it and making a decision. Unless of course you know some javascript. And... I do. So I can't come up with a title, I'll let the code choose a random(ish) one for us.
11+
12+This is done with an array of nouns, an array of adjectives and a prefix to the title. The basic idea is to randomly concatenate those terms together. Since the prefix would become repetitive, I've set it to only show up 50% of the times.
13+
14+Here is the code wrote.
15+
16+{% highlight javascript %}
17+ // for convenience, return a number within the range. Pass the noFloor for a float.
18+ function rrange(min, max, noFloor) {
19+ var result = Math.random() * (max - min) + min;
20+ return noFloor ? result : Math.floor(result);
21+ }
22+ // generate the title.
23+ function randomTitle() {
24+ // some nouns and adjectives...
25+ var nouns = [ 'Functions', 'Loops', 'Bugs', 'Monkeys', 'Duck', 'String', 'Integers' ],
26+ adjs = [ 'Flying', 'Sleeping', 'Typing', 'Parsing', 'Lost', 'Delicious', 'Forgotten' ],
27+ // random ints
28+ x = rrange(1, nouns.length) - 1,
29+ y = rrange(1, adjs.length) - 1,
30+ // coin flip for the prefix
31+ prefix = Math.random() > 0.5 ? 'The ' : '',
32+ // concat it all
33+ title = prefix + adjs[y] + ' ' + nouns[x];
34+ // set the title
35+ $('#random-title').text(title);
36+ }
37+ $(function () { randomTitle() })
38+{% endhighlight %}
39+
40+There is more that can be done, like adding more nouns and adjectives and different title constructs. If you decide to extend this, or have done something like it, please share your nouns and adjectives.
blog.html+6−0
@@ -7,6 +7,12 @@ layout: default
77 {% include buttons.html %}
88 </div>
99 <div class="span10">
10+ <div class="page-header">
11+ <small class="muted pull-right">
12+ Sorted by date, new to old.
13+ </small>
14+ <h3>All posts</h3>
15+ </div>
1016 <ul class="nav nav-pills nav-stacked">
1117 {% for post in site.posts %}
1218 <li>
css/styles.css+8−4
@@ -1,15 +1,19 @@
11 /* google web font */
22 h1 {
33 visibility: hidden;
4- font-family: 'Quantico', sans-serif;
5- font-weight: 700;
4+ font-family: 'Racing Sans One', sans-serif;
5+ font-weight: 400;
66 }
77 .custom-font {
88 visibility: hidden;
9- font-family: 'Quantico', sans-serif;
9+ font-family: 'Racing Sans One', sans-serif;
1010 font-weight: 400;
1111 }
1212 /* navbar padding */
1313 body {
14- padding-top: 50px;
14+ padding-top: 70px;
15+}
16+/* nice hero-unit */
17+.hero-unit {
18+ background: transparent;
1519 }
index.html+13−5
@@ -2,6 +2,19 @@
22 layout: default
33 ---
44
5+<div class="hero-unit">
6+ <a id="reload-title" class="pull-right" href="#">
7+ <i class="icon-refresh tipped" title="Get a new title!"></i>
8+ </a>
9+ <h1>
10+ <span id="random-title">Loading...</span>
11+ </h1>
12+ <p class="lead">
13+ I coulnd't think of a title, so a random one is generated.
14+ <a href="/2013/02/25/random-title-generator.html">This</a> is how I did it.
15+ </p>
16+</div>
17+
518 <div class="row-fluid">
619 <div class="span2">
720 <h3>Recent</h3>
@@ -20,11 +33,6 @@ layout: default
2033
2134 </div>
2235 <div class="span10">
23- <h3>Sean's github page</h3>
24- <p class="lead">
25- This is where I'm active online. I test my projects here, and I'm constantly tweaking this site. On ocasion I write about code.
26- </p>
27-
2836 <div id="edshelf-widget"></div><script src="//edshelf.com/widgets/collection?id=10408&height=550"></script>
2937
3038 <div class="media">
js/script.js+72−32
@@ -2,11 +2,71 @@
22 /*global $: true */
33 (function () {
44 'use strict';
5+ function rrange(min, max, noFloor) {
6+ var result = Math.random() * (max - min) + min;
7+ return noFloor ? result : Math.floor(result);
8+ }
9+ function loadStyle(url, fn) {
10+ var style = document.createElement('style'),
11+ fi;
12+ style.textContent = '@import "' + url + '"';
13+ fi = setInterval(function () {
14+ try {
15+ style.sheet.cssRules; // <--- MAGIC: only populated when file is loaded
16+ fn(style);
17+ clearInterval(fi);
18+ } catch (e) {}
19+ }, 10);
20+ $('head').prepend(style);
21+ }
22+ function setNavActive() {
23+ var items = $('.nav-main li'),
24+ page = location.pathname.match(/\/[a-zA-Z0-9\.\-]+$/);
25+ if (page) {
26+ page = page[0];
27+ if (page === '/work.html') {
28+ items.last().addClass('active');
29+ } else {
30+ items.first().addClass('active');
31+ }
32+ }
33+ }
34+ function setRandomTitle() {
35+ var nouns = [ 'Functions', 'Loops', 'Bugs', 'Monkeys', 'Duck', 'String', 'Integers' ],
36+ adjs = [ 'Flying', 'Sleeping', 'Typing', 'Parsing', 'Lost', 'Delicious', 'Forgotten' ],
37+ x = rrange(1, nouns.length) - 1,
38+ y = rrange(1, adjs.length) - 1,
39+ prefix = Math.random() > 0.5 ? 'The ' : '',
40+ middle = Math.random() > 0.66666 ? ' of ' : ' ',
41+ title = Math.random() > 0.5 ?
42+ prefix + adjs[y] + ' ' + nouns[x] :
43+ prefix + nouns[x] + middle + adjs[y];
44+ $('#random-title').text(title);
45+ }
46+ function setLightSwitch(fn) {
47+ var saved = window.localStorage ? window.localStorage.getItem('colorscheme') : 'light',
48+ style = saved || 'light';
49+ function color(done) {
50+ var url = '/css/bootstrap.' + style + '.min.css';
51+ $('#colorscheme').remove();
52+ loadStyle(url, function (node) {
53+ node.id = 'colorscheme';
54+ if (done) { done(); }
55+ });
56+ }
57+ color(fn);
58+ $('#light-switch').click(function (ev) {
59+ ev.preventDefault();
60+ style = style === 'light' ? 'dark' : 'light';
61+ if (window.localStorage) { window.localStorage.setItem('colorscheme', style); }
62+ color();
63+ });
64+ }
565 // google web font, no flash of unstyled text
666 window.WebFontConfig = {
7- google: { families: ['Quantico:400,400italic,700,700italic:latin'] },
67+ google: { families: ['Quantico:400,400italic,700,700italic:latin', 'Racing+Sans+One::latin'] },
868 active: function () {
9- // font is ready, assume jquery
69+ // font is ready, dom is ready, init and display
1070 $(function () {
1171 // on your css make sure you make all the elements that us this font visibility: hidden;
1272 $('h1, .custom-font').css({ visibility: 'visible' });
@@ -22,36 +82,16 @@
2282 s = document.getElementsByTagName('script')[0];
2383 s.parentNode.insertBefore(wf, s);
2484 }());
25- function setNavActive() {
26- var items = $('.navbar .nav li'),
27- page = location.pathname.match(/\/[a-zA-Z0-9\.\-]+$/);
28- if (page) {
29- page = page[0];
30- if (page === '/work.html') {
31- items.last().addClass('active');
32- } else {
33- items.first().addClass('active');
34- }
35- }
36- }
3785 $(function () {
38- $('body').show();
39- setNavActive();
86+ setLightSwitch(function () {
87+ setNavActive();
88+ setRandomTitle();
89+ $('body').show();
90+ $('.tipped').tooltip({ placement: 'left', animation: true });
91+ $('#reload-title').click(function (ev) {
92+ ev.preventDefault();
93+ setRandomTitle();
94+ });
95+ });
4096 });
41- /* save for later
42- function loadStyle(url, fn) {
43- var style = document.createElement('style'),
44- fi;
45- style.textContent = '@import "' + url + '"';
46- fi = setInterval(function () {
47- try {
48- style.sheet.cssRules; // <--- MAGIC: only populated when file is loaded
49- fn();
50- clearInterval(fi);
51- } catch (e) {}
52- }, 10);
53-
54- $('head').prepend(style);
55- }
56- */
5797 }());