Skip to content

Instantly share code, notes, and snippets.

View boyvanamstel's full-sized avatar
👋
Hi there

Boy van Amstel boyvanamstel

👋
Hi there
View GitHub Profile
@boyvanamstel
boyvanamstel / Many to Many in RoR
Created March 7, 2011 14:02
Two ways to do many to many relations in RoR
# http://blog.hasmanythrough.com/2006/4/20/many-to-many-dance-off
# Join Table: Simple Associations
# Table:
create_table "dancers_movies", :id => false do |t|
t.column "dancer_id", :integer, :null => false
t.column "movie_id", :integer, :null => false
end
@boyvanamstel
boyvanamstel / HTML5 Boilerplate v1.0
Created March 27, 2011 18:43
Minimal HTML5 template
<!doctype html>
<!--[if lt IE 7 ]> <html class="no-js ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]> <html class="no-js ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]> <html class="no-js ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>RSS Title</title>
<description>This is an example of an RSS feed</description>
<link>http://www.someexamplerssdomain.com/main.html</link>
<lastBuildDate>Mon, 06 Sep 2010 00:01:00 +0000 </lastBuildDate>
<pubDate>Mon, 06 Sep 2009 16:45:00 +0000 </pubDate>
<item>
@boyvanamstel
boyvanamstel / Future Posts in Wordpress
Created April 11, 2011 16:16
Displays posts in the future.
<?php
$my_query = new WP_Query('post_status=future&order=DESC&showposts=5');
if ($my_query->have_posts()) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php the_date(); ?> - <?php the_title(); ?>
<?php endwhile;
}
// Source: http://www.studionashvegas.com/tutorial/displaying-future-posts-in-wordpress/
?>
@boyvanamstel
boyvanamstel / gist:980981
Created May 19, 2011 15:10
Longitude Latitude in Rails
class Poi < ActiveRecord::Migration
def self.up
create_table :pois, :id => :poi_id do |t|
t.column :longitude, :decimal, :precision => 10, :scale => 7
t.column :latitude, :decimal, :precision => 10, :scale => 7
end
end
def self.down
drop_table :pois
@boyvanamstel
boyvanamstel / gist:981012
Created May 19, 2011 15:24
Convert erb to haml
find . -name '*.html.erb' | xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}' | bash
find . -name "*.html.erb" -exec rm -rf {} \;
@boyvanamstel
boyvanamstel / gist:986357
Created May 23, 2011 07:35
Android Facebook SDK hash generation
# Release
keytool -exportcert -alias [alias] -keystore [keystore] | openssl sha1 -binary | openssl enc -a -e
# Debug
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl enc -a -e
Password: android
@boyvanamstel
boyvanamstel / gist:986670
Created May 23, 2011 13:15
Multiple relations to the same model in Rails
# Model User:
has_many :questions
has_many :comments
# Questions to which the user is an expert a.k.a. 'questions to me'
has_many :experts, :dependent => :destroy
has_many :questionstome, :through => :experts, :source => :question
# This allows you to do things like this:
# u = User.first
@boyvanamstel
boyvanamstel / gist:988766
Created May 24, 2011 14:14
Export and import SQLite
# export
sqlite3 database.sqlite .dump > output.sql
# import
cat output.sql | sqlite3 database.sqlite
@boyvanamstel
boyvanamstel / gist:989628
Created May 24, 2011 20:47
Resize image in Android
// Source: http://www.anddev.org/resize_and_rotate_image_-_example-t621.html
// load the origial BitMap (500 x 500 px)
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.android);
int width = bitmapOrg.width();
int height = bitmapOrg.height();
int newWidth = 720;