Skip to content

Instantly share code, notes, and snippets.

View pascalchevrel's full-sized avatar

Pascal Chevrel pascalchevrel

View GitHub Profile
<?php
namespace Utils;
class Strings
{
public static function substringsCount($string, $dots)
{
str_replace($dots, '#\#\#', strip_tags($string), $val);
return $val;
@pascalchevrel
pascalchevrel / gist:5906395
Last active December 19, 2015 05:48
check fx version is valid
<?php
function isValidFirefoxDownload() {
if (!isset($_GET['product'])) {
return false;
}
global $config;
$versionDetails = (int) str_replace('firefox-', '', $_GET['product']);
@pascalchevrel
pascalchevrel / gist:6069330
Last active December 20, 2015 04:18
Script to convert a Serbian Cyrillic repo to Latin script
#!/usr/bin/env php
<?php
// Transliteration to Serbian requires ICU library >= 5.0
if (php_sapi_name() != 'cli') {
die('Nope');
}
$targetFolder = (isset($argv[1])) ? $argv[1] : 'sr-Latn'; // target folder
@pascalchevrel
pascalchevrel / gist:6099342
Last active December 20, 2015 08:19
Use bugzilla advanced search results returned as CSV as a simple and efficient read-only API to query Bugzilla. The official bugzilla API doesn't allow searching all of the fields, the advanced query page does. In most of the cases, what you want are bug numbers and bug titles from a search query. Since we can now get bug numbers from an arbitra…
<?php
function getBugsFromCSV($csv, $full = false)
{
$shortBugs = $fullBugs = $temp = [];
if (($handle = fopen($csv, 'r')) !== false) {
while (($data = fgetcsv($handle, 300, ',')) !== false) {
if ($data[0] == 'bug_id') {
@pascalchevrel
pascalchevrel / gist:7299680
Created November 4, 2013 08:26
This is a PHP function to check if a file has a UTF8 encoding, UTF8 files that only contain ASCII characters are detected as us-ascii by PHP.
<?php
function isUTF8($filename)
{
$info = finfo_open(FILEINFO_MIME_ENCODING);
$type = finfo_buffer($info, file_get_contents($filename));
finfo_close($info);
return ($type == 'utf-8' || $type == 'us-ascii') ? true : false;
}
@pascalchevrel
pascalchevrel / gist:9623606
Last active August 29, 2015 13:57
String Distribution for Firefox Aurora, based on data from Transvision
<?php
function cleanEntity($entity)
{
$component = explode('/', $entity);
array_pop($component); // suppress entity
$component = array_filter(
$component,
function($val) { return $val != 'chrome'; }
);
@pascalchevrel
pascalchevrel / gist:9933685399402b6682c9
Created September 19, 2014 11:36
Extract json files from the l10n API and generate text files for Transvision use
<?php
// Script should not be called from the Web
if (php_sapi_name() != 'cli') {
die('Nope');
}
$settings = parse_ini_file(__DIR__ . '/../config/config.ini');
if(! isset($settings['l10nwebservice'])) {
error_log('L10n Web service variable in config.ini is not defined');
@pascalchevrel
pascalchevrel / gist:8bd3a0dfa284ca349ddf
Created September 30, 2014 13:26
Get Timestamp of svn commit for a file
<?php
function getSVNCommitTimestamp($file)
{
exec("svn info --xml ${file} 2>/dev/null", $output, $return_code);
if ($return_code) {
return false;
}
@pascalchevrel
pascalchevrel / gist:7906edeb30e63f2e9506
Created October 1, 2014 14:37
patch to import the Legal string
diff --git a/classes/Langchecker/LangManager.php b/classes/Langchecker/LangManager.php
index ce450ad..bdebe36 100644
--- a/classes/Langchecker/LangManager.php
+++ b/classes/Langchecker/LangManager.php
@@ -385,4 +385,16 @@ class LangManager
return $result;
}
+
+ public static function importTransvisionEntity($repository, $english, $entity)
@pascalchevrel
pascalchevrel / gist:463fc7b1f0382f187820
Last active December 22, 2021 23:39
Example script to use with github webhooks to update a site when pushing on master
<?php
/* Webhook to update a repo for each push on GitHub. */
date_default_timezone_set('Europe/Paris');
$header_match = 'HTTP_X_HUB_SIGNATURE';
$secret_key = 'my_secret_key_in_github_webhook';
$branch = 'master';
function logHookResult($message , $success = false) {