Skip to content

Instantly share code, notes, and snippets.

View lionelB's full-sized avatar
🪂
Working from home

Lionel lionelB

🪂
Working from home
View GitHub Profile
@lionelB
lionelB / GameBoardUtils.as
Created February 3, 2011 09:19
useful little snippets
/*
Find the number of complete row and col from a number of objects
*/
col = Math.sqrt(_nbCards);
if (_nbCards % col > 0)
{
while (_nbCards % ++col != 0){};
}
@lionelB
lionelB / download.php
Created February 7, 2011 10:51
A download script supporting http 1.1 partial content (206)
<?php
function getMime($path)
{
$mime = '';
if (function_exists("mime_content_type"))
{
return mime_content_type($filename);
}
else if (function_exists("finfo_open"))
{
@lionelB
lionelB / ActivityIndicator.as
Created February 18, 2011 14:14
A simple osx-like activity indicator
package ui.utils
{
import flash.display.CapsStyle;
import flash.display.LineScaleMode;
import flash.display.Shape;
import flash.events.Event;
import flash.utils.clearInterval;
import flash.utils.getTimer;
import flash.utils.setInterval;
package com.lafabrick.utils
{
public class Lemme
{
public function Lemme()
{
super();
}
public static function lematize( s : String ) : String
@lionelB
lionelB / getIndexesOf.as
Created August 23, 2012 16:40
Get index of string
protected function getIndexesOf(word : String, source : String = "") : Vector.<int>
{
var results : Vector.<int> = new Vector.<int>();
var startIndex : int = source.indexOf( word, 0 );
while( startIndex != -1 )
{
results.push(startIndex);
startIndex = source.indexOf( word, startIndex + word.length );
}
var rows = document.getElementsByClassName('row');
[].forEach.call( rows, function(row, i){
if(i%2) {
row.addEventListener("click", function(event) {
alert('Je suis la ligne numéro' + i);
});
}
});
function capitalize(str) {
return str.replace(/^[a-zàáâãäåçèéêëìíîïðòóôõöùúûüýÿñ]/, function(x) {
return String.fromCharCode(x.charCodeAt(0) - 32);
});
}
@lionelB
lionelB / test.capitalize.js
Created May 1, 2013 16:57
Capitalize test uppercase() vs fromCharCode()
function capitalize(str) {
return str.substr(0, 1).toUpperCase() + str.substr(1)
}
function capitalize2(str) {
return str.replace(/^[a-zàáâãäåçèéêëìíîïðòóôõöùúûüýÿñ]/, function(x) {
return x.toUpperCase();
});
}
@lionelB
lionelB / strip_accent.js
Created May 1, 2013 17:25
Strip accent (and lower case)
function strip_accent( str ) {
var acc = "ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿñ".split('')
, min = "aaaaaaceeeeiiiiooooouuuuyaaaaaaceeeeiiiioooooouuuuyyn".split('')
, l = acc.length
, i = 0;
for(; i < l ; i++) {
str = str.replace( new RegExp(acc[i], "g"), min[i]);
}