Skip to content

Instantly share code, notes, and snippets.

View tomasr8's full-sized avatar

Tomas R tomasr8

  • CERN
  • Geneva
  • 13:25 (UTC +02:00)
View GitHub Profile
@tomasr8
tomasr8 / smart-recruiters.user.js
Last active February 14, 2023 12:41
User script which lets you view candidate's resumes without having to open their profile. Saves you time and extra clicks.
// ==UserScript==
// @name Smart Recruiters
// @version 1
// @match https://www.smartrecruiters.com/app/jobs/details/*
// @grant none
// @run-at document-idle
// ==/UserScript==
const BASE_URL = "https://www.smartrecruiters.com"
const CANDIDATE_LIST = "sr-list-content ul.st-candidate-list"
@tomasr8
tomasr8 / redux.js
Created February 17, 2020 11:41
Redux in 30 lines
function createStore(reducer) {
const store = {
state: {},
reducer,
dispatch(action) {
this.state = this.reducer(action, this.state)
}
}
store.dispatch({})
@tomasr8
tomasr8 / fsm.js
Last active October 16, 2016 17:53
Simple finite state machine (FSM) implementation
"use strict";
function FSM(states, start, accepting) {
function _accepts(state, word) {
if (word === "") {
return accepting.indexOf(state) !== -1;
}
return _accepts(states[state][word[0]], word.slice(1));
@tomasr8
tomasr8 / freeze.js
Last active August 18, 2016 11:16
make object immutable
"use strict";
function freeze(obj) {
if(typeof obj !== "object") {
return;
}
Object.freeze(obj);
for (let prop in obj) {
if (obj.hasOwnProperty(prop)) {
freeze(obj[prop]);
@tomasr8
tomasr8 / ndarray.js
Created August 18, 2016 08:16
n-dimensional array creation for js
function NdArray(...args) { // n-1 args are dimensions, last argument is the fill value
if(args.length === 2) {
return new Array(args[0]).fill(args[1]);
}
let arr = [];
let newArgs = args.slice(1);
for(let i = 0; i < args[0]; i++) {
arr.push(NdArray(...newArgs));
}
return arr;
@tomasr8
tomasr8 / parens.js
Created August 16, 2016 14:53
parens validator
let log = console.log.bind(console);
let test1 = "(asf(s)f)jkl(kl)l)l";
let test2 = "(hf)fh()(h(hf()h)gh)fffh";
log(validate(test1)); // --> false
log(validate(test2)); // --> true
function validate(str) {
str = str.replace(/[^\(\)]/g, "");
@tomasr8
tomasr8 / curry.js
Last active August 16, 2016 12:06
Javascript currying
Function.prototype.curry = function(...args) {
const fn = this;
return function (...additional) {
return fn.apply(this, args.concat(additional));
};
};
// examples
function greet(word, name) {
console.log(word, name);