Skip to content

Instantly share code, notes, and snippets.

Avatar
🙏

Nami W namiwang

🙏
View GitHub Profile
@namiwang
namiwang / extends grape desc with header.md
Last active Apr 16, 2022
grape extends desc auth header
View extends grape desc with header.md

instead of

desc 'some endpoint', {
  headers: { Authorization: {
    description: 'Bearer JWT',
    required: true
  }
}}
get do
@namiwang
namiwang / gist:40bb4838eacf40d508312fdf716aa6b9
Created Jun 12, 2020
ruby, gem, bundler without rvm in ubuntu
View gist:40bb4838eacf40d508312fdf716aa6b9
# ruby
sudo apt install ruby ruby-dev
# env and path
export GEM_HOME=$HOME/.gem/
PATH="/home/ubuntu/.gem/bin:$PATH"
View gist:e5427857644611b5e24795c830095bc7
```
yarn add select2
```
# /javascript/stylesheets/active_admin.scss
```
@import 'select2/dist/css/select2';
```
# /javascript/active_admin.js
@namiwang
namiwang / resource_menu_humanable.rb
Last active Apr 8, 2020
active admin menu humanable with count
View resource_menu_humanable.rb
# admin/concerns/resource_menu_humanable
module ResourceMenuHumanable
extend ActiveSupport::Concern
def self.included(base)
base.menu label: -> { "#{base.config.resource_class.model_name.human}#{base.config.resource_class.count})" }
end
end
@namiwang
namiwang / patch_simulating_middleware.rb
Created Oct 16, 2019
rack middleware to simulate PATCH by _name=POST
View patch_simulating_middleware.rb
class PatchSimulatingMiddleware
def initialize app
@app = app
end
def call env
request = Rack::Request.new(env)
if request.post? && ( request.params['_name'] == 'patch' )
request.set_header 'REQUEST_METHOD', 'PATCH'
@namiwang
namiwang / patch_simulating_middleware.rb
Last active Aug 27, 2019
middleware to simulate PATCH method with a POST when client doesn't support it
View patch_simulating_middleware.rb
class PatchSimulatingMiddleware
def initialize app
@app = app
end
def call env
request = Rack::Request.new(env)
if request.post? && ( request.params['_name'] == 'patch' )
request.set_header 'REQUEST_METHOD', 'PATCH'
View gist:54334bf7f40f8d8e7dda0b9b5430719e
azure storage cors set -a [-beep-] -k [-beep-] --blob --cors "[{\"AllowedOrigins\":\"http://foo.bar.com, http://127.0.0.1:1234\",\"AllowedMethods\":\"GET\",\"MaxAgeInSeconds\":\"86400\",\"AllowedHeaders\":\"*\",\"ExposedHeaders\":\"*\"}]"
@namiwang
namiwang / uploader.sh
Created May 30, 2016
azure blob folder uploader
View uploader.sh
#!/bin/bash
# https://stackoverflow.com/questions/28900078/upload-multi-file-from-linux-folder-to-azure-blob-storage
export AZURE_STORAGE_ACCOUNT='your_account'
export AZURE_STORAGE_ACCESS_KEY='your_access_key'
export container_name='name_of_the_container_to_create'
export source_folder=~/path_to_local_file_to_upload/*
@namiwang
namiwang / ideagen
Created Jun 23, 2013
get random words from matrix67's idea generator
View ideagen
require 'nokogiri'
require 'open-uri'
50.times do
page = Nokogiri::HTML(open("http://www.matrix67.com/ideagen/"))
word = page.css('body .main p').children[0].to_s.gsub("\r",'').gsub("\n",'').gsub("\t",'').split('的')[1]
File.open('words','a'){ |file| file.write(word+"\n") }
end