Skip to content

Instantly share code, notes, and snippets.

@smolak
smolak / isbn-verifier.clj
Created February 9, 2020 22:26
ISBN 10 and 13 verifier
(ns isbn-verifier)
(defn- digits
"Splits ISBN 10 string into collection of digits"
[col]
(keep #(cond
(Character/isDigit %) (Character/getNumericValue %)
(= \X %) 10)
col))
// I have some testing framework in the scope
// Questions below:
// 1. Should the description be like it is here, in first `it`, or with `only` word added:
// "should return Fizz when the number is divisible only by 3"
// That would imply that the number is divisible by 3 only, which is technically not true, as it is divisible
// by 1 as well, and some numbers, e.g. 6, 9, and so on, are divisible by themselves.
it('should return Fizz when the number is divisible by 3', () => {
// 2. Is that name enough, having `any` in it, to be complete in what numbers are producing `fizz`.
// There is also a matter of adding `only` (similar to case #1) having `anyNumberDivisibleOnlyBy3`.
@smolak
smolak / jssr-draft.md
Last active February 10, 2019 19:00
JSSR draft

JSSR - JavaScript Standards Recommendation

Mind: this is a draft

Why?

I have found PHP's PSRs to be a very good idea when it comes to having some sorts of standards for commonly performed tasks. Wheter it's logging, caching or performing HTTP calls.

What are PSRs? Here's a short description taken from Wikipedia:

describe('executing handlers', () => {
context('for synchronous handlers', () => {
it('should happen in sequence', async () => {
const hook1 = {
event: 'preEventName',
handler: sinon.spy()
};
const hook2 = {
event: 'preEventName',
handler: sinon.spy()
@smolak
smolak / human-readable.js
Created August 16, 2017 18:02
Human readable code
const allRequiredMethodsArePresent = requiredMethods.every(methodIsPresentIn(adaptersMethods));
#!/usr/bin/env node
console.log('Howdy!');
#!/usr/bin/env bash
echo "Howdy!"
echo "Howdy!"
(function() {
var defineProperty = 'defineProperty' in Object,
defineGetter = '__defineGetter__' in Object;
// mini polyfill for defining getters
Object.extend({
defineGetter: function(object, prop, fn) {
if (defineProperty) {
@smolak
smolak / Delete.php
Created May 16, 2013 21:30
ZFCRUD user delete form
<?php
class Admin_Form_Delete extends Zend_Form
{
public function init()
{
$cancel = new Zend_Form_Element_Button('cancel');
$cancel->setLabel('Hold your horses, do not delete this fella!')
->setAttrib('onClick',