Skip to content

Instantly share code, notes, and snippets.

View ocombe's full-sized avatar

Olivier Combe ocombe

View GitHub Profile

Locl Individual Contributor License Agreement

In order to clarify the intellectual property license granted with Contributions from any person or entity, Locl ("Locl") must have a Contributor License Agreement ("CLA") on file that has been signed by each Contributor, indicating agreement to the license terms below. This license is for your protection as a Contributor as well as the protection of Locl; it does not change your rights to use your own Contributions for any other purpose.

You accept and agree to the following terms and conditions for Your present and future Contributions submitted to Locl. Except for the license granted herein to Locl and recipients of software distributed by Locl, You reserve all right, title, and interest in and to Your Contributions.

  1. Definitions.

"You" (or "Your") shall mean the copyright owner or legal entity authorized by the copyright owner that is making this Agreement with Locl. For legal entities, the entity making a Contribution and all other entities that c

Bitwise operations

Using bitwise operations is blazing fast for the VM. Here is how you can encode and use information: First you have to determine the number of operations that you need to encode to know how many bits you need, based on 2^n, where n is the number of bits, and 2^n the number of operations that you can encode.

For example if I have 5 operations, I need 3 bits (2^2 = 4 operations, and 2^3 = 8 operations). Then you can encode the operations in an enum. Each operation will have a different number, and you need to shift each operation by 32 bits - n (for 5 operations and 3 bits, we will shift by 32-3=29).

@ocombe
ocombe / __workaround.node.ts
Created March 13, 2017 13:02
ng2-translate + universal
/*
* THIS IS TEMPORARY TO PATCH 2.1.1+ Core bugs
*/
/* tslint:disable */
let __compiler__ = require('@angular/compiler');
import {__platform_browser_private__} from '@angular/platform-browser';
import {__core_private__} from '@angular/core';
let patch = false;
if(!__core_private__['ViewUtils']) {
@ocombe
ocombe / translateLSLoader.ts
Created April 27, 2016 08:55
ng2-translate file loader with localstorage to speed up things
import {TranslateLoader} from "ng2-translate/ng2-translate";
import {Observable} from "rxjs/Observable";
import {Response, Http} from "angular2/http";
export class TranslateLSLoader implements TranslateLoader {
constructor(private http: Http, private prefix: string = 'i18n', private suffix: string = '.json') {}
/**
* Gets the translations from the localStorage and update them with the ones from the server
* @param lang
@ocombe
ocombe / translateUniversalLoader.ts
Last active May 11, 2023 07:01
ng2-translate file loader for Angular Universal (server side)
import {TranslateLoader} from "ng2-translate/ng2-translate";
import {Observable} from "rxjs/Observable";
import fs = require('fs');
export class TranslateUniversalLoader implements TranslateLoader {
constructor(private prefix: string = 'i18n', private suffix: string = '.json') {}
/**
* Gets the translations from the server
* @param lang
@ocombe
ocombe / Permanent Node HTTP server.md
Last active January 29, 2020 10:33
Daemon for permanent node web server on linux.

Install dependencies:

sudo npm i -g forever http-server

Add server script

Copy startServer.js to /usr/lib/startServer.js

Create service

  • Copy content of http-server in /etc/init.d/http-server
@ocombe
ocombe / util.js
Created June 19, 2013 16:00
Forwards events from a floating mask element to the underlying iframe document, except for scrolling
/**
* Forwards events from a floating mask element to the underlying document, except for scrolling
*/
var forwardEvents = function(element) {
var evts = [ 'dblclick', 'click', 'tap', 'doubletap', 'mousedown', 'mouseup' ];
for(var i = 0, l = evts.length; i < l; i++) {
element.addEventListener(evts[i], function(event) {
var s = [0, 0],
x = Ext.num(event.pageX, event.clientX) - s[0],
@ocombe
ocombe / directive.js
Created June 13, 2013 13:37
Angular directive for limited textarea (limited in number of octets in this case)
angular.module('grid').
directive('limitedtextarea', function () {
var byteLength = function (s, b, i, c) {
for (b = i = 0; c = s.charCodeAt(i++); b += c >> 11 ? 3 : c >> 7 ? 2 : 1);
return b;
}
return {
restrict: 'E',
replace: true,
@ocombe
ocombe / gist:5771999
Last active December 18, 2015 10:59
Inline jQuery search filter
$(document).ready(function() {
// let's make a case insensitive contains selector
$.extend($.expr[':'], {
'containsi': function(elem, i, match, array) {
return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
}
});
});
//filter results based on query
@ocombe
ocombe / gist:5771995
Last active December 18, 2015 10:59
Detect text encoding in php
public function findEncoding($str) {
$tab = array("UTF-8", "ASCII", "ISO-8859-1");
foreach ($tab as $i) {
foreach ($tab as $j) {
$chain .= " [iconv('$i','$j','$str'): " . iconv($i, $j, "$str") . "] ";
}
}
return $chain;
}