Skip to content

Instantly share code, notes, and snippets.

View Sephi-Chan's full-sized avatar

Romain Tribes Sephi-Chan

  • Nîmes, France
View GitHub Profile
We couldn’t find that file to show.
class Stater
def initialize(*roles)
@state = 0
@roles = roles
end
def current
@roles[@state % @roles.size]
@Sephi-Chan
Sephi-Chan / minify_resources.rb
Created April 12, 2011 22:42
Package and minify Javascript and CSS files.
#!/usr/bin/env ruby
module MinifyResources
CSS_BLOB = 'public/blob.css'
CSS_DIR = 'public/css'
CSS_LIST = 'public/css/manifest.txt'
CSS_FILES = File.exists?(CSS_LIST) ? IO.read(CSS_LIST).scan(/\S+/) : Dir.chdir(CSS_DIR){ Dir['*.css'] }
JS_BLOB = 'public/blob.js'
JS_DIR = 'public/js'
@Sephi-Chan
Sephi-Chan / server.js
Created May 2, 2011 20:33
HTTP request with Node
var body = JSON.stringify({
uuid: item.uuid
}),
options = {
host: settings.callback.hostname,
port: settings.callback.port,
path: settings.callback.path,
method: 'POST',
headers: {
'X-PQS-Secret-Key': settings.callback.secretKey,
@Sephi-Chan
Sephi-Chan / server.js
Created May 2, 2011 21:21
ProductionQueue server
var settings = {
callback: {
hostname: '127.0.0.1',
port: 4567,
path: '/finish_production',
secretKey: 'my-super-secret-key'
}
}
var http = require('http'),
class Array
# Count occurences of values in the array.
# Return it as a hash.
#
# [1, 1, "foo", :bar, 1, :bar].count_occurrences # => {1 => 3, "foo" => 1, :bar => 2}
def count_occurrences
h = self.group_by { |x| x }
Hash[h.map { |k, v| [ k, v.length ] } ]
end
end
diff --git a/activesupport/lib/active_support/core_ext/array/grouping.rb b/activesupport/lib/active_support/core_ext/array/grouping.rb
index 4cd9bfa..b6ccef5 100644
--- a/activesupport/lib/active_support/core_ext/array/grouping.rb
+++ b/activesupport/lib/active_support/core_ext/array/grouping.rb
@@ -97,4 +97,16 @@ class Array
results
end
end
+
+
@Sephi-Chan
Sephi-Chan / response.js
Created June 4, 2011 15:32
Youtube video response
{
"version": "1.0",
"encoding": "UTF-8",
"entry": {
"xmlns": "http://www.w3.org/2005/Atom",
"xmlns$media": "http://search.yahoo.com/mrss/",
"xmlns$gd": "http://schemas.google.com/g/2005",
"xmlns$yt": "http://gdata.youtube.com/schemas/2007",
"gd$etag": "W/\"DEMFR347eCp7ImA9WhZVFkQ.\"",
"id": {
Training Load (0.2ms) SELECT `trainings`.* FROM `trainings` WHERE ((begin_at <= '2011-06-15 09:00:00' AND '2011-06-15 09:00:00' <= finish_at)
OR (begin_at <= '2011-06-15 11:00:00' AND '2011-06-15 11:00:00' <= finish_at))
Training Load (0.2ms) SELECT `trainings`.* FROM `trainings` WHERE `trainings`.`trainer_id` = 3
ig
.module('game.entities.levelchange')
.requires('impact.entity')
.defines ->
window.EntityLevelchange = ig.Entity.extend
_wmDrawBox: true
_wmBoxColor: 'rgba(0, 0, 255, 0.7)'
size:
x: 8