Skip to content

Instantly share code, notes, and snippets.

View MathRivest's full-sized avatar

Mathieu Rivest MathRivest

  • Turo
  • Montreal, QC, Canada
  • 00:58 (UTC -04:00)
  • X @MathRivest
View GitHub Profile
@MathRivest
MathRivest / hashtable-es6.js
Created October 8, 2017 13:04
hashtable-es6 created by mathrivest - https://repl.it/L7T7/8
class HashTable {
constructor(size) {
this.buckets = Array(size);
this.numBuckets = this.buckets.length;
}
hash(key) {
let total = 0;
for (var i = 0; i < key.length; i++) {
total += key.charCodeAt(i);
@MathRivest
MathRivest / bst-es6.js
Created September 16, 2017 22:52
bst-es6 created by mathrivest - https://repl.it/LMAV/0
class BST {
constructor(value) {
this.value = value;
this.left = null;
this.right = null;
}
insert(value) {
if (value <= this.value) {
if (!this.left) {
@MathRivest
MathRivest / big-o-es5.js
Last active September 11, 2017 14:27
Big O Notation in javascript examples
// Constant runtime - Big O Notation: "O (1)"
function log(array) {
console.log(array[0]);
console.log(array[1]);
}
log([1, 2, 3, 4]);
log([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
@MathRivest
MathRivest / linked-list-es5.js
Last active October 30, 2022 10:23
Javascript ES5 Linked List implementation
function LinkedList() {
this.head = null;
this.tail = null;
}
function Node(value, next, prev) {
this.value = value;
this.next = next;
this.prev = prev;
}
@MathRivest
MathRivest / rebalance.js
Last active June 15, 2017 17:42
Rebalance script
let items = [
{
id: 1,
symbol: 'a',
cost: 25,
target: 50,
value: 500,
},
{
id: 1,
@MathRivest
MathRivest / angular-back-button.js
Last active August 29, 2015 14:24
Back button directive for AngularJS. Using the $state
'use strict';
angular.module('fitcart.common.directives', []).directive('backButton', require('./back-button'));
module.exports = /*@ngInject*/ function($window) {
return {
restrict: 'E',
replace: true,
template: '<button class="btn-back" ng-show="!hideBack" ng-cloak>Back</button>',
controller: function($scope, $state){
@MathRivest
MathRivest / show.html.twig
Last active August 29, 2015 14:11
Social shares -Add fb-root to dom -Add fb-appid to body tag (data-fb-appid="123") -Initialize in your main js
<a href="#"
class="b-social-action"
data-facebook-share
data-url="{{app.request.uri}}"
data-title="{{page_title}}">
<i>F</i><span class="name">Facebook</span>
</a>
<a href="https://twitter.com/intent/tweet?text={{page_title}}&amp;url={{app.request.uri}}"
class="b-social-action"
data-twitter-share>
@MathRivest
MathRivest / config.js
Last active August 29, 2015 14:10
Event debugging for angular.js
app.config(function ($provide) {
$provide.decorator('$rootScope', function ($delegate) {
var backup = $delegate.$emit;
$delegate.$emit = function () {
console.log.apply(console, arguments);
backup.apply(this, arguments)
}
return $delegate;
@MathRivest
MathRivest / style.scss
Created August 29, 2014 14:45
Distribute divs horizontally
.wrapper{
text-align: justify;
text-justify: distribute-all-lines;
.item{
display:inline-block;
}
&:after {
content: "";
width: 100%;
display: inline-block;
@MathRivest
MathRivest / delay.js
Created August 12, 2014 14:46
Delay Fonction
$field.on('keyup', function(event){
delay(function(){
alert('Delayed for 1 second')
}, 1000);
});
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);