Skip to content

Instantly share code, notes, and snippets.

Avatar
🐼
fuzzy logic

Josh Goodall inopinatus

🐼
fuzzy logic
View GitHub Profile
View DirectUpload.vue
<template lang='pug'>
div.drop-zone(:class='{dragging: isDragging }'
@dragover.prevent='dragover'
@dragenter.prevent='dragover'
@drop.prevent.stop='onDrop'
@dragleave.prevent='dragleave')
div(:class='{ hidden: uploadInProgress }' @click='openFileBrowser')
slot
i {{label}}
input(type='file' :multiple='multiple' ref='input' style='display: none')
@devloco
devloco / download-pdf.js
Last active Nov 3, 2021
Download a PDF via POST with Fetch API
View download-pdf.js
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;
}
@andyyou
andyyou / rails_webpacker_bootstrap_expose_jquery.md
Last active Oct 5, 2021
Rails 5.2 with webpacker, bootstrap, stimulus starter
View rails_webpacker_bootstrap_expose_jquery.md

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
@jrunning
jrunning / base58.rb
Last active Nov 17, 2020
UUID to Base 58 in Ruby
View base58.rb
# 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 Jul 25, 2021
AWS Lambda function for forwarding SNS notifications to Slack
View function.js
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'};
@ryndel
ryndel / .float-label.md
Last active Nov 2, 2017
Float label css only solution
View .float-label.md

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:

<field is="float-label" label="Your name" type="text" id="name" name="name" 
View big_decimal_inspect_override.rb
class BigDecimal
def inspect
"#<BigDecimal: #{to_s}>"
end
end
@inopinatus
inopinatus / hstore_accessor.rb
Last active Feb 22, 2019
hstore accessor class method for AR
View hstore_accessor.rb
# 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 Mar 22, 2012
Incredibly stupid Ruby tricks. Please add more.
View stupid.rb
# The worst possible way to memoize something.
class X
def value
@value = really_expensive_operation
def value; @value end
@value
end
end
@steveclarke
steveclarke / gist:1411146
Created Nov 30, 2011
Git: Setting up a Remote Repository and Doing Initial Push
View gist:1411146

Setup remote repository:

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

On local machine:

cd my_project