Skip to content

Instantly share code, notes, and snippets.

Olivier Combe ocombe

Block or report user

Report or block ocombe

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile

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 / __workaround.node.ts
Created Mar 13, 2017
ng2-translate + universal
View __workaround.node.ts
/* 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 / translateLSLoader.ts
Created Apr 27, 2016
ng2-translate file loader with localstorage to speed up things
View translateLSLoader.ts
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 / translateUniversalLoader.ts
Last active Jul 21, 2019
ng2-translate file loader for Angular Universal (server side)
View translateUniversalLoader.ts
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 / Permanent Node HTTP
Last active Feb 18, 2019
Daemon for permanent node web server on linux.
View Permanent Node HTTP

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 / util.js
Created Jun 19, 2013
Forwards events from a floating mask element to the underlying iframe document, except for scrolling
View util.js
* 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 / directive.js
Created Jun 13, 2013
Angular directive for limited textarea (limited in number of octets in this case)
View directive.js
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 / gist:5771999
Last active Dec 18, 2015
Inline jQuery search filter
View gist:5771999
$(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 / gist:5771995
Last active Dec 18, 2015
Detect text encoding in php
View gist:5771995
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;
You can’t perform that action at this time.