Skip to content

Instantly share code, notes, and snippets.

View redthree's full-sized avatar

Gonzalo Castillo redthree

  • Santiago, Chile
  • 22:31 (UTC -04:00)
View GitHub Profile
@redthree
redthree / removeDiacritics.js
Last active January 24, 2020 13:22
Remove accents/diacritics from string
const str = "áàâäãéèëêíìïîóòöôõúùüûñçăşţ";
str.normalize('NFKD').replace(/[^\w]/g, '');
// 'aaaaaeeeeiiiiooooouuuuncast'
@redthree
redthree / base64_encode.js
Created September 10, 2018 20:35
Encoding to base64
function base64_encode(file) {
var bitmap = fs.readFileSync(file);
return new Buffer(bitmap).toString('base64');
}
@redthree
redthree / text-vibrance.js
Created September 5, 2018 22:38
Text vibrance effect
export function vibrance(ele, min, max, speed, color1 = '#ff1e9b', color2 = '#1eccff'){
const self = this;
setTimeout(() => {
let rndNumber = self._randomIntFromInterval(min, max);
let strStyle = rndNumber + 'px 0px 0px ' + color1 + ', -' + rndNumber + 'px 0px 0px ' + color2;
ele.style.textShadow = strStyle;
self._vibrance(ele, min, max, speed, color1 = '#ff1e9b', color2 = '#1eccff');
}, speed);
}
@redthree
redthree / hasSpecial.js
Last active September 4, 2018 22:45
Check if a string has a special character
// Check if a string has a special character
export function hasSpecial(str){
const iChars = "~`!#$%^&*+=-[]\\\';,/{}|\":<>?";
for (let i = 0; i < str.length; i++) {
if (iChars.indexOf(str.charAt(i)) != -1) {
return true;
}
}
return false;
}
@redthree
redthree / rndColor.js
Created August 27, 2018 14:34
rndColor
function rndColor(){return '#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6);}
@redthree
redthree / expressjs_http_https
Created August 8, 2018 19:14
expressjs_http_https
var fs = require('fs');
var http = require('http');
var https = require('https');
var privateKey = fs.readFileSync('sslcert/server.key', 'utf8');
var certificate = fs.readFileSync('sslcert/server.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};
var express = require('express');
var app = express();
@redthree
redthree / shuffleArray.js
Created July 27, 2018 20:27
shuffle array
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
@redthree
redthree / react_native-fix_run_android.txt
Created May 16, 2018 23:46
Fix react-native run-android
$ mkdir android/app/src/main/assets
$ react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
$ react-native run-android
@redthree
redthree / Searchbox.js
Created January 23, 2018 12:05
ReactJS Searchbox Component
// Libraries
import React, { Component } from 'react';
import PropTypes from 'prop-types';
class SearchBox extends Component {
constructor(props) {
super(props);
this.onChange = this.onChange.bind(this);
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
}