Skip to content

Instantly share code, notes, and snippets.

View olegp's full-sized avatar

Oleg Podsechin olegp

View GitHub Profile
{
"future": {
"date": "22/05/2025",
"link": "http://bit.ly/helsinkictos"
},
"members": 49
}
{
"future": {
"date": "18/05/2025",
"link": "http://bit.ly/helsinkihn"
},
"members": 24
}
@olegp
olegp / background.js
Created September 20, 2018 20:31
Active tab change detection in Chrome Extension
let activeTabId, lastUrl, lastTitle;
function getTabInfo(tabId) {
chrome.tabs.get(tabId, function(tab) {
if(lastUrl != tab.url || lastTitle != tab.title)
console.log(lastUrl = tab.url, lastTitle = tab.title);
});
}
chrome.tabs.onActivated.addListener(function(activeInfo) {
@olegp
olegp / raffle.js
Last active March 20, 2018 17:43
((p) => p[Math.floor(Math.random() * (p.length))])(`
Alberto Marchetti
Daniel Schildt
Ekaterina Dorrer
Fernando Girón
Iines Piesala
Joonas Haaparanta
Majedul Hoque Ruman
Margarita Obraztsova
Matti Vakkilainen
<div>
<form ng-submit="submit()">
<input ng-model="text">
<button>Submit</button>
</form>
<ul>
<li ng-repeat="message in messages">{{message.time}} {{message.text}}</li>
</ul>
</div>
@olegp
olegp / placeholder.js
Created December 30, 2015 12:52
input placeholder shim
if (!('placeholder' in document.createElement('input'))) {
angular.module('directives').directive('placeholder', ['$timeout', function($timeout) {
return function($scope, $element, $attrs) {
var hasFocus = false;
$element.bind('focus', function() {
hasFocus = true;
if ($element.hasClass('placeholder')) {
$timeout(function() {
$element.val('');
$element.removeClass('placeholder');
@olegp
olegp / prettify.js
Last active December 29, 2015 10:26
JS code for generating SEO friendly URL fragments
function prettify(text) {
return text.toLowerCase()
.replace(/ä/g, 'a')
.replace(/ö/g, 'o')
.replace(/å/g, 'a')
.replace(/[^0-9a-z]+/g, '-')
.replace(/^-*(.*?)-*$/, '$1');
}
@olegp
olegp / test.js
Created December 15, 2014 20:32
test
module.exports = "test";
var express = require('express');
var app = express();
var messages = [
{ date: new Date(), text: "Hello World" }
];
app.use('/', express.static('./'));
app.get('/api/', function(req, res){
@olegp
olegp / similarity.js
Created March 4, 2012 20:35
String Similarity
// JS port of http://www.catalysoft.com/articles/StrikeAMatch.html
function similarity(str1, str2) {
function letterPairs(str) {
var pairs = [];
for ( var i = 0; i < str.length - 1; i++) {
pairs.push(str.substr(i, i + 2));
}
return pairs;
}