Skip to content

Instantly share code, notes, and snippets.

View mikaa123's full-sized avatar

Michael Sokol mikaa123

  • Paris, France
View GitHub Profile
@mikaa123
mikaa123 / rake run_jar
Created March 23, 2011 17:14
Rake task to generate and run a jar with Rawr
desc "Generates and run the jar file"
task :run_jar do
puts `rake rawr:clean`
puts `rake rawr:jar`
puts `java -jar deployement/jar/filename.jar
end
@mikaa123
mikaa123 / gist:1382896
Created November 21, 2011 15:08
Executable Markdown file example

Lilplateform

To create lilplateform, we will be using ray library. It's a game engine DSL made for ruby. Have a look (here)[http://mon-ouie.github.com/projects/ray.html] if you don't know about it yet.

All the dependencies of the game are defined in the project's Gemfile, under the "game" group. Let's require them now.

@mikaa123
mikaa123 / my_swt_program.rb
Created June 12, 2012 18:12
SWT + JRuby Bootstrap example
require 'java'
require 'swt'
# Each Swt application need a display to interact with the operating system.
# It provides the event loop.
display = Swt::Widgets::Display.new
# Let's create a new window. It's called "Shell" in Swt vocabulary.
# Note that we pass in a display.
shell = Swt::Widgets::Shell.new(display)
@mikaa123
mikaa123 / gist:4109789
Created November 19, 2012 09:19
Samsung TV cookie module
// Use this as a black-box module to replace joshlib!utils/cookie when developing with
// Samsung TV.
//
// It returns a function to be called with the following parameters:
// name - The key to store.
// data - The value associated with this key.
//
// NOTE: In order to use, you need to expose <script src='$MANAGER_WIDGET/Common/af/2.0.0/loader.js' type='text/javascript'></script>
// in your index file.
//
@mikaa123
mikaa123 / function_strategies.js
Last active December 14, 2015 16:48
Strategies as functions
// Greeter is a class of object that can greet people.
// It can learn different ways of greeting people through
// 'Strategies.'
//
// This is the Greeter constructor.
var Greeter = function(strategy) {
this.strategy = strategy;
};
// Greeter provides a greet function that is going to
@mikaa123
mikaa123 / strategy_classes.js
Created March 8, 2013 16:53
Strategies as classes
// We can also leverage the power of Prototypes in Javascript to create
// classes that act as strategies.
//
// Here, we create an abstract class that will serve as the interface
// for all our strategies. It isn't needed, but it's good for documenting
// purposes.
var Strategy = function() {};
Strategy.prototype.execute = function() {
throw new Error('Strategy#execute needs to be overridden.')
@mikaa123
mikaa123 / template_methods.js
Created March 8, 2013 17:03
Strategies and template methods
// Since the GreetingStrategy#execute method uses methods to define its algorithm,
// the Template Method pattern, we can subclass it and simply override one of those
// methods to alter the behavior without changing the algorithm.
var PoliteGreetingStrategy = function() {};
PoliteGreetingStrategy.prototype = Object.create(GreetingStrategy.prototype);
PoliteGreetingStrategy.prototype.sayHi = function() {
return "Welcome sir, ";
};
@mikaa123
mikaa123 / strategies_and_if.js
Created March 8, 2013 17:15
strategies and if statements
var greeters = [
new Greeter(new BoredGreetingStrategy()),
new Greeter(new PoliteGreetingStrategy()),
new Greeter(new FriendlyGreetingStrategy()),
];
greeters.forEach(function(greeter) {
// Since each greeter knows its strategy, there's no need
// to do any type checking. We just greet, and the object
// Taken from http://passportjs.org
var passport = require('passport')
// Each authentication mechanism is provided as an npm package.
// These packages expose a Strategy object.
, LocalStrategy = require('passport-local').Strategy
, FacebookStrategy = require('passport-facebook').Strategy;
// Passport can be instanciated using any Strategy.
@mikaa123
mikaa123 / asog_sounds.go
Created March 30, 2013 16:30
Unmarshal JSON from API.
// vim:set sw=4 sts=4:
package main
import (
"io/ioutil"
"net/http"
"encoding/json"
"time"
"os/exec"
)