Skip to content

Instantly share code, notes, and snippets.

View atesgoral's full-sized avatar

Ateş Göral atesgoral

View GitHub Profile
@atesgoral
atesgoral / LICENSE.txt
Last active May 20, 2025 16:27 — forked from 140bytes/LICENSE.txt
Date formatter that uses human-readable date instance getters instead of cryptic Y/M/D etc. tokens
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Ates Goral <http://magnetiq.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@atesgoral
atesgoral / LICENSE.txt
Created May 24, 2011 17:35 — forked from 140bytes/LICENSE.txt
XML-escape given string
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Ates Goral <http://magnetiq.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@atesgoral
atesgoral / LICENSE.txt
Created May 21, 2011 08:48 — forked from 140bytes/LICENSE.txt
Variable-argument string formatter with {token} syntax that supports object properties and argument indices
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Ates Goral <http://magnetiq.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@atesgoral
atesgoral / sensitive.rb
Created November 12, 2020 02:28
A way to prevent accidental leaking of sensitive data
class Sensitive
@@being_responsible = false
def initialize(value)
@value = value
end
def to_s
@@being_responsible ? @value : '[REDACTED]'
end
@atesgoral
atesgoral / js-style-guide.md
Last active September 20, 2020 16:47
Deterministic JavaScript Style Guide

Deterministic JavaScript Style Guide

This the style that I use and proselytize. Everything is derived from just a handful of core rules:

  1. 4 spaces for indentation.
  2. Code block opening curly brackets (braces) are on the same line (as function, for, if, etc.)
  3. Add spaces around operators and statements.
  4. Add spaces inside brackets for array and object literals.
  5. Don't add spaces inside parenthesis.
@atesgoral
atesgoral / keybinding.json
Last active April 23, 2020 04:06
Visual Studio Code custom task for running current MiniTest
{ "key": "shift+ctrl+t", "command": "workbench.action.tasks.runTask", "args": "Run current MiniTest" }
@atesgoral
atesgoral / validate_upc.js
Last active July 5, 2019 14:32
UPC-12 validation
['101010101012','614141000036','036000241457','613119000030','614141000035','036000241450','614141000030']
.map(upc=>!(upc.split``.reduce((u,p,c)=>u+p*(3+c*2&3),0)%10))
// [true, true, true, true, false, false, false]
module SofterDeleteAllDependents
extend ActiveSupport::Concern
included do
before_destroy :softer_delete_associations, prepend: true
end
private
def softer_delete_associations
function getQueryParams(qs) {
qs = qs.replace(/\+/g, " ");
var params = {},
re = /[?&]?([^=]+)=([^&]*)/g,
tokens;
while (tokens = re.exec(qs)) {
params[decodeURIComponent(tokens[1])]
= decodeURIComponent(tokens[2]);
}