Skip to content

Instantly share code, notes, and snippets.

View litil's full-sized avatar

Guillaume Lambert litil

View GitHub Profile
@litil
litil / isObjectEqual.js
Created April 28, 2017 09:30
ReactJS - Object Comparison
// from https://medium.com/@nesbtesh/react-best-practices-a76fd0fbef21
export const isObjectEqual = (obj1, obj2) => {
if(!isObject(obj1) || !isObject(obj2)) {
return false;
}
if (obj1 === obj2) {
return true;
}
@litil
litil / gist:a0f248dbe8334f1f4874986868fc28f4
Created March 31, 2017 14:39
Convert WoneF database file into a Solr formatted synonyms file
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as ET
import re
import unicodedata
# This method adds all given synonyms into the correct dictionary entry.
def extendDictEntry(dict, key, xmlSynonyms):
for child in xmlSynonyms:
childText = child.text.encode('utf-8')
@litil
litil / [Java] VideoUtils
Created March 31, 2014 13:42
[Java] VideoUtils
package com.litil.utils;
/**
* This class contains methods concerning videos. For now, it can help
* you check if an url is valid and convert a "classic" url to an
* "embed" one.
*
*/
public class VideoUtils {
@litil
litil / [Java] Readable file size
Created February 21, 2014 10:37
Calculate the size of a file and return it in a readable format
public static String readableFileSize(long size) {
if(size <= 0) return "0";
final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
int digitGroups = (int) (Math.log10(size)/Math.log10(1024));
return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}
@litil
litil / [JS] All browsers log method
Created February 19, 2014 21:04
This simple logging method works in all modern browsers
function log() {
try {
// tries to log the message using the most common method
console.log.apply(console, arguments);
} catch(e) {
// catches any failure in logging
try {
// tries to log the Opera way
opera.postError.apply(opera, arguments);
package com.urmoments.api.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
/**
* This class contains methods concerning the Date. It contains a method which