Skip to content

Instantly share code, notes, and snippets.

View simonjodet's full-sized avatar

Simon Jodet simonjodet

View GitHub Profile
@simonjodet
simonjodet / default.twig
Created September 19, 2012 11:30
Gumdrop: Example of post layout
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% if page.title != 'Home' and page.title != '' %}{{ page.title }} - {% endif %}Simon's Blog</title>
<link rel="stylesheet" href="/tools/bootstrap.min.css?cache={{ "now"|date("U") }}" type="text/css" charset="utf-8"/>
<link rel="stylesheet" href="/style/css/style.css?cache={{ "now"|date("U") }}" type="text/css" charset="utf-8"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="generator" content="Gumdrop">
<meta name="author" content="Simon Jodet">
<link rel="alternate" type="application/rss+xml" href="http://feeds.feedburner.com/jodet/blog"/>
@simonjodet
simonjodet / atom.xml.twig
Created September 19, 2012 12:09
Gumdrop: Example of index page and RSS feed
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Simon's Blog</title>
<link href="http://blog.jodet.com/atom.xml" rel="self"/>
<link href="http://blog.jodet.com/"/>
<updated>{{ pages|reverse[0].date|date(DATE_ATOM) }}</updated>
<id>http://blog.jodet.com/</id>
<author>
<name>Simon Jodet</name>
</author>
@simonjodet
simonjodet / Database.php
Created October 19, 2012 08:33
Mockery - Partially mocking class's own methods
<?php
class Database
{
/**
* @var \Doctrine\DBAL\Connection
*/
private $conn;
public function __construct(\Silex\Application $app)
@simonjodet
simonjodet / app.php
Created October 21, 2012 16:35
Silex automatic post-registration user authentication
<?php
$app['security.firewalls'] = array(
'user_firewall' => array(
'pattern' => new \Application\UserRequestMatcher($app['request']),
'form' => array('login_path' => '/login', 'check_path' => '/authenticate'),
'logout' => array('logout_path' => '/logout'),
'users' => $app->share(function () use ($app)
{
return new \Application\UserProvider($app);
}),
@simonjodet
simonjodet / test.sh
Created December 13, 2012 14:15
Test for Gumdrop installer
# PHP 5.3+ (CLI) required. Should work with stock PHP on Mac OS 10.8.
cd /tmp
php -r "$(curl -s https://raw.github.com/simonjodet/gumdrop/develop/installer.php|tail -n +2)"
@simonjodet
simonjodet / create_new_file.txt
Created December 18, 2012 07:48
Edit a file on Github through the API
curl --user "simonjodet" -i --data '{"content": "new test","encoding": "utf-8"}' https://api.github.com/repos/simonjodet/sandbox/git/blobs
HTTP/1.1 201 Created
Server: nginx
Date: Tue, 18 Dec 2012 08:13:45 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Status: 201 Created
Location: https://api.github.com/repos/simonjodet/sandbox/git/blobs/6e6ab611ec78d425b37fcb26c3d817d71e58afcb
ETag: "4774fa91e9a71a16564b43460b72d649"
@simonjodet
simonjodet / iPhoto_launcher.sh
Last active December 11, 2015 18:48
This code mounts the USB Hard Drive where the iPhoto library is stored, launch iPhoto then unmount the drive when iPhoto is closed.
VOL='/dev/'$(diskutil list | grep -Eo '.*Apple_HFS Pictures.*' | grep -Eo 'disk.s.')
hdiutil mountvol $VOL
open -W /Applications/iPhoto.app
hdiutil detach $VOL
@simonjodet
simonjodet / vagrant_setup.sh
Last active December 12, 2015 09:49
Ubuntu minimal setup for a Vagrant base box
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar -xvzf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125/
./configure --prefix=/usr/local
make
make install
@simonjodet
simonjodet / add_to_iTunes.scpt
Created June 1, 2013 18:57
This is how you add a video to iTunes as a TV Show with AppleScript. Save it as "add_to_iTunes.scpt" using /Applications/Utilities/AppleScript Editor Run it with "osascript add_to_iTunes.scpt /absolute/path/to/video/file.mp4"
on run {input}
tell application "iTunes"
set newFile to input as POSIX file
set newAddition to (add newFile)
tell newAddition to set video kind to TV show
end tell
end run
@simonjodet
simonjodet / ngtoggle.js
Last active August 29, 2015 14:02
Angular directive to have an element toggle another element's display on click
'use strict';
angular.module('myApp').directive(
'ngToggle',
function() {
var factory = {
restrict: 'A',
link: function postLink(scope, element, attributes) {
$(element).on('click', function(event) {
event.preventDefault();