Skip to content

Instantly share code, notes, and snippets.

View inopinatus's full-sized avatar
🐼
fuzzy logic

Josh Goodall inopinatus

🐼
fuzzy logic
View GitHub Profile
class BigDecimal
def inspect
"#<BigDecimal: #{to_s}>"
end
end
@ryndel
ryndel / .float-label.md
Last active November 2, 2017 11:45
Float label css only solution

Float label

A web component that create a CSS-only floating label for input tags

Usage

The syntax for generating a float-label input is as follows:

@inopinatus
inopinatus / hstore_accessor.rb
Last active February 22, 2019 08:32
hstore accessor class method for AR
# include from an initializer
module HstoreAccessor
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def hstore_accessor(hstore_attribute, *keys)
Array(keys).flatten.each do |key|
@jbarnette
jbarnette / stupid.rb
Created March 22, 2012 15:57
Incredibly stupid Ruby tricks. Please add more.
# The worst possible way to memoize something.
class X
def value
@value = really_expensive_operation
def value; @value end
@value
end
end
@jrunning
jrunning / base58.rb
Last active November 17, 2020 03:55
UUID to Base 58 in Ruby
# base58_to_int and int_to_base58 loosely based on base58 gem by Douglas F. Shearer
# https://github.com/dougal/base58
ALPHABET = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ".chars
BASE = ALPHABET.size
def base58_to_int(base58_val)
base58_val.chars
.reverse_each.with_index
.reduce(0) do |int_val, (char, index)|
@vgeshel
vgeshel / function.js
Last active February 9, 2022 09:19
AWS Lambda function for forwarding SNS notifications to Slack
console.log('Loading function');
const https = require('https');
const url = require('url');
// to get the slack hook url, go into slack admin and create a new "Incoming Webhook" integration
const slack_url = 'https://hooks.slack.com/services/...';
const slack_req_opts = url.parse(slack_url);
slack_req_opts.method = 'POST';
slack_req_opts.headers = {'Content-Type': 'application/json'};
@andyyou
andyyou / rails_webpacker_bootstrap_expose_jquery.md
Last active August 9, 2022 07:38
Rails 5.2 with webpacker, bootstrap, stimulus starter

Rails 5.2 with webpacker, bootstrap, stimulus starter

This gist will collects all issues we solved with Rails 5.2 and Webpacker

Create Project

# Last few parameters(--skip-* part) is only my habbit not actully required
$ rails new <project_name> --webpack=stimulus --database=postgresql --skip-coffee --skip-test
@steveclarke
steveclarke / gist:1411146
Created November 30, 2011 21:54
Git: Setting up a Remote Repository and Doing Initial Push

Setup remote repository:

ssh git@example.com
mkdir my_project.git
cd my_project.git
git init --bare

On local machine:

cd my_project

@inopinatus
inopinatus / uu58.rb
Last active October 11, 2023 20:21
Convert UUIDs to/from base58
module Uu58
# Convert a string UUID to a base58 string representation.
#
# Output will be padded up to 22 digits if necessary.
#
# Behaviour is undefined if passing something other than a 128-bit
# hex string in network order with optional interstitial hyphens.
def self.uuid_to_base58(uuid, alphabet = SecureRandom::BASE58_ALPHABET)
ary = uuid.delete("-").to_i(16).digits(58).reverse
ary.unshift(0) while ary.length < 22
@devloco
devloco / download-pdf.js
Last active January 10, 2024 11:09
Download a PDF via POST with Fetch API
let fnGetFileNameFromContentDispostionHeader = function (header) {
let contentDispostion = header.split(';');
const fileNameToken = `filename*=UTF-8''`;
let fileName = 'downloaded.pdf';
for (let thisValue of contentDispostion) {
if (thisValue.trim().indexOf(fileNameToken) === 0) {
fileName = decodeURIComponent(thisValue.trim().replace(fileNameToken, ''));
break;
}