Skip to content

Instantly share code, notes, and snippets.

Avatar
💯

Bruno brunobuddy

💯
View GitHub Profile
@brunobuddy
brunobuddy / simple-toggle-item-selection.ts
Created Aug 7, 2019
Simple Toggle Item from Array (add or remove) in TS / JS ES6
View simple-toggle-item-selection.ts
const selectedItemIds: number[] = []
toggleSelect(itemId: number) {
if (this.selectedItemIds.includes(itemId)) {
// Remove item from Array if already selected
const index = this.selectedItemIds.indexOf(itemId)
this.selectedItemIds.splice(index, 1)
} else {
// Adds item to Array
this.selectedItemIds.push(itemId)
@brunobuddy
brunobuddy / cookie-modal.ts
Created Apr 30, 2019
Angular TS Component for GRPD Compliant Cookie Modal Dialog
View cookie-modal.ts
@brunobuddy
brunobuddy / cookie-modal.html
Last active May 3, 2019
Angular HTML Template for GRPD Compliant Cookie Modal Dialog
View cookie-modal.html
@brunobuddy
brunobuddy / enableOrDisableGoogleAnalytics.html
Last active Apr 30, 2019
Custom script for Google Tag Manager to enable or disable Google Analytics tracking based on the presence of the "accept_cookies" cookie
View enableOrDisableGoogleAnalytics.html
<script>
// If no cookie
if( document.cookie.indexOf('accept_cookies=') == -1) {
// Disable Google Analytics
window['ga-disable-UA-XXXXXXXX-X'] = true;
}
else {
// Enable Google Analytics
window['ga-disable-UA-XXXXXXXX-X'] = false;
}
@brunobuddy
brunobuddy / BetDemocracy.sol
Created Jun 21, 2018
BetDemocracy V 0.1 Contract
View BetDemocracy.sol
pragma solidity 0.4.17;
import "./JsmnSolLib.sol";
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
import "github.com/Arachnid/solidity-stringutils/src/strings.sol";
contract BetDemocracy is usingOraclize {
using strings for *;
@brunobuddy
brunobuddy / validateRegistrationNumber.ts
Created Jun 8, 2018
TypeScript SIRET Validation Script (French company registration number)
View validateRegistrationNumber.ts
// Returns true if valid, false if not. Note that registrationNumber param is a string (usually provided by HTML imput)
validateRegistrationNumber(registrationNumber: string): boolean {
if (registrationNumber.length !== 14) {
return false
}
let sum = 0
let digit: number
for (let i = 0; i < registrationNumber.length; i++) {
if (i % 2 === 0) {
digit = parseInt(registrationNumber.charAt(i), 10) * 2
View smoothscroll.js
/*-----------------------------------*\
#Smooth Scroll
\*-----------------------------------*/
$('.smooth-scroll').click( function() {
var page = $(this).attr('href');
var headerHeight = 80;
var speed = 400; // Durée de l'animation (en ms)
$('html, body').animate( { scrollTop: $(page).offset().top - headerHeight }, speed ); // On récupére l'espace perdu avec le header.
return false;