Skip to content

Instantly share code, notes, and snippets.

View alexwebgr's full-sized avatar
😎

Alexandros alexwebgr

😎
View GitHub Profile
@alexwebgr
alexwebgr / Session.js
Last active September 26, 2022 14:21
Simple wrapper for localStorage
/**
* @author alexwebgr < https://github.com/alexwebgr >
* @desc the word 'Session' is used as a convention in order to avoid overriding
* the Storage or localStorage objects since localStorage is persisted in the browser
* even if the browser window closes or even the system restarts
* the only way to delete localStorage is manually
*/
var Session =
{
@alexwebgr
alexwebgr / world-topo.json
Created April 9, 2014 10:01
topoJson json file with country codes, capitals, longitude, longitude
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alexwebgr
alexwebgr / gist:73ec7708b3433b5e534c
Created November 16, 2015 09:10
Force restart of date time widget on top bar ubuntu
pkill -f datetime
@alexwebgr
alexwebgr / gist:f1d76c5f7c0cf3103112066b08bd9f6e
Last active April 1, 2016 19:12
Concatenate consecutive characters followed by the number of characters if it is over 1
var input = 'aaaabbbbccccpqesrt';
var compressedString = '';
var s = input.match(/([a-zA-Z])\1*/g) || [];
s.forEach(function(value) {
var k = '';
if(value.length > 1) {
k = value.length;
}
compressedString += value.charAt(0) + k;
<%= select 'time_range', 'id', Hash.map { |r| [r[:label], r[:name]] }, {selected: params[:time_range], include_blank: true}, {'data-placeholder': 'Select Time Range'} %>
@alexwebgr
alexwebgr / growable_text.js
Created May 30, 2019 08:43
resize a textarea as you type
$("textarea.growable")
.on('keyup paste input', function () {
let self = $(this);
let offset = self.innerHeight() - self.height();
if (self.innerHeight() < this.scrollHeight) {
//Grow the field if scroll height is smaller
self.height(this.scrollHeight - offset);
} else {
//Shrink the field and then re-set it to the scroll height in case it needs to shrink
@alexwebgr
alexwebgr / signature.js
Created May 30, 2019 08:47
Digital signature field
class SignTool {
constructor() {
this.initVars();
this.initEvents();
}
initVars() {
this.canvas = $('#canvas')[0];
this.ctx = this.canvas.getContext("2d");
this.isMouseClicked = false;
@alexwebgr
alexwebgr / search_form.js
Created May 30, 2019 09:06
autocomplete search function
var keys = [8,
46,
48,
49,
50,
51,
52,
53,
54,
55,
// requires https://medialize.github.io/URI.js
function updateURL(url, params) {
let new_url = new URI(url);
$.each(params, function (value) {
if (params[value] !== undefined) {
new_url.setSearch(value, params[value]);
} else {
new_url.removeSearch(value);
@alexwebgr
alexwebgr / video_loader.js
Created May 30, 2019 09:23
Load youtube videos async
let videos = $(".wpl-youtube");
$.each(videos, function () {
let self = $(this);
let thumbnail = self.find('img');
let play = self.find('.wpl-play');
// Based on the YouTube ID, we can easily find the thumbnail image
thumbnail.attr('src', 'https://i.ytimg.com/vi/' + self.attr('data-id') + '/0.jpg');
play.on({