Skip to content

Instantly share code, notes, and snippets.

View johanbrook's full-sized avatar
🌴

Johan Brook johanbrook

🌴
View GitHub Profile
<!-- MODAL BOX -->
<section class="modal">
<a class="close">×</a>
<h2>New mail</h2>
<form action="" id="new-mail" method="POST">
<div class="floats">
<label for="from">From (your e-mail address)</label>
<input id="from" type="email" />
</div>
def next_message(messages)
begin
debugger
message = messages.queued.next
date = message.arrived_at
rescue NoMethodError => e
date = nil
message = new_message_path
end
date = date ? " in #{time_ago_in_words(date)}" : "when you write one!"
def create
@message = Message.new(params[:message])
if @message.save
if session[:sent]
@messages = current_user.messages.sent.arrived_at_asc.paginate(:page => params[:page], :per_page => 5)
else
@messages = current_user.messages.queued.created_at_desc.paginate(:page => params[:page], :per_page => 5)
end
flash[:success] = "Mail is successfully queued and will be sent on #{@message.arrived_at}"
<nav>
<ul>
<?php $class = 'class="current"';?>
<li <?php if(is_page("about") echo $class; ?>><a href="<?php link_to("about");?>">About</a></li>
</ul>
</nav>
@johanbrook
johanbrook / gist:761909
Created January 1, 2011 18:36
Convert an ICNS file to PNG with alpha transparency
sips -s format png /Applications/Safari.app/Contents/Resources/compass.icns --out /Users/Johan/Desktop/safari.png
@johanbrook
johanbrook / gist:772137
Created January 9, 2011 23:24
Kolla vid "and post_type = 'post'". Jag vill ha ut _både_ posttypen "post" och "quickie". How, oh how?
"SELECT DISTINCT MONTH( post_date ) AS month ,
YEAR( post_date ) AS year,
COUNT( id ) as post_count FROM $wpdb->posts
WHERE post_status = 'publish' and post_date <= now( )
and post_type = 'post'
GROUP BY month , year
ORDER BY post_date DESC"
@johanbrook
johanbrook / gist:775506
Created January 12, 2011 01:16
Provides a nice retro "awful green-on-black" style for http://kodapp.com
/*
* This is the default style of Kod. If you wish to modify this to your liking,
* make a copy and put it in ~/.kod/mystyle.css then tell Kod where to find it
* by setting a configuration key:
*
* $ defaults write se.hunch.kod style/url ~/.kod/mystyle.css
*
* You might need to restart Kod for changes to take effect. Then, simply open
* your ~/.kod/mystyle.css in Kod -- when edited and saved Kod will
* automatically reload the style, thus you see the effect of your alterations.
@johanbrook
johanbrook / gist:809484
Created February 3, 2011 13:48
The beauty of Sass: creating loops directly in the stylesheet. In this one I've created a @for loop which is shifting the background sprite for each section. No need for a bunch of background-position declarations.
& > section{
float: left;
margin-right: $lineheight;
width: $wideColumn;
background: transparent url(style/images/frontpage-icons.png) no-repeat left top;
padding-top: $column;
@for $i from 2 through 4 {
&:nth-child(#{$i}){
@johanbrook
johanbrook / gist:810058
Created February 3, 2011 19:51
A simple plugin for truncating long text strings.
(function($) {
/**
* A simple jQuery I wrote to truncate long links (in the post footers, amongst others).
*
* Usage:
* $("a.long-links").truncate( [ {limit: 40, truncationText: "..."} ] );
*
*/
@johanbrook
johanbrook / gist:814776
Created February 7, 2011 17:29
Two snippets for making an element fixed after scrolling over a certain point. Saving for reference.
// @rem's solution
$(document).ready(function () {
var $comment = $('#comment'),
top = $comment.offset().top - parseFloat($comment.css('marginTop').replace(/auto/, 0)),
$window = $(window);
$window.scroll(function (event) {
// what the y position of the scroll is