Skip to content

Instantly share code, notes, and snippets.

@t18n
t18n / tsconfig.json
Last active November 6, 2024 02:02 — forked from vemarav/tsconfig.json
[Example tsconfig.json] Tsconfig.json with description #typescript
{
"compilerOptions": {
/* Basic Options */
"target": "esnext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": [
"esnext",
"dom"
] /* Specify library files to be included in the compilation. */,
// "allowJs": true, /* Allow javascript files to be compiled. */
@carlosramireziii
carlosramireziii / allow_content_type.rb
Last active September 22, 2023 21:39
A validator and RSpec matcher for restricting an attachment’s content type using Active Storage
require "rspec/expectations"
RSpec::Matchers.define :allow_content_type do |*content_types|
match do |record|
matcher.matches?(record, content_types)
end
chain :for do |attr_name|
matcher.for(attr_name)
end
@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
@xgotyou
xgotyou / images_helper.rb
Last active October 5, 2018 17:49
Rails images for retina and other high dpi displays using srcset
module ImagesHelper
# Outputs html img tag with srcset attribute for 2x image based on original
# src. Use naming convention ex. having 'image.jpg', 2x image should be named
# '[email protected]'. If there's no image.jpg or [email protected] exception will be
# thrown by Rails asset pipeline.
def retina_image(src, options = {})
src2x = src.gsub(/(^.+)(\.(jpg|png)$)/, '\1@2x\2')
image_tag src, options.merge(srcset: "#{image_url(src2x)} 2x")
end
end
@gentamura
gentamura / _form.html.erb
Created December 6, 2014 03:10
Cloudinary + Carrierwave + Heroku + Railsでの画像を手軽に利用する方法 ref: http://qiita.com/GenTamura84/items/38cf899827bba050a21c
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
@exocode
exocode / gist:9302aed84fb6f6ee6c16
Created September 14, 2014 13:39 — forked from skorianez/gist:1308103
jCrop and Carrierwave
# https://github.com/gzigzigzeo/carrierwave-meta
# Integrating CarrierWave with JCrop
# Let implement the behavior like at this demo: deepliquid.com/projects/Jcrop/demos.php?demo=thumbnail
# The uploader:
class CropUploader < SobakaUploader
include CarrierWave::Meta
# Crop source is a source image converted from original which could be bigger than source area (left image in the example).
version :crop_source do
@sscarduzio
sscarduzio / relog.sh
Created August 24, 2014 21:20
BtWiFi_with_FON automatic login written as a bash script. I have this running every 10 minutes on my raspberry pi
#!/bin/bash
# CONF
DBG=true
[email protected]
RELOG_PASSW=xxxxxxxxxxxxxxx
# END CONF
@gshaw
gshaw / carrier_wave.rb
Created August 14, 2014 19:06
CarrierWave initialization file for testing with fixtures and support S3 in staging and production.
# NullStorage provider for CarrierWave for use in tests. Doesn't actually
# upload or store files but allows test to pass as if files were stored and
# the use of fixtures.
class NullStorage
attr_reader :uploader
def initialize(uploader)
@uploader = uploader
end
@youngbrioche
youngbrioche / images_helper.rb
Last active February 8, 2024 08:15
Responsive images helper using srcset in Rails
module ImagesHelper
# Acts as a thin wrapper for image_tag and generates an srcset attribute for regular image tags
# for usage with responsive images polyfills like picturefill.js, supports asset pipeline path helpers.
#
# image_set_tag 'pic_1980.jpg', { 'pic_640.jpg' => '640w', 'pic_1024.jpg' => '1024w', 'pic_1980.jpg' => '1980w' }, sizes: '100vw', class: 'my-image'
#
# => <img src="/assets/ants_1980.jpg" srcset="/assets/pic_640.jpg 640w, /assets/pic_1024.jpg 1024w, /assets/pic_1980.jpg 1980w" sizes="100vw" class="my-image">
#
def image_set_tag(source, srcset = {}, options = {})
srcset = srcset.map { |src, size| "#{path_to_image(src)} #{size}" }.join(', ')
@17twenty
17twenty / fixSQL.py
Created February 5, 2014 19:32
How to fix problems with sqlite3.OperationalError: disk I/O error in Python
"""
You'll most likely notice you have a something.db-journal file - that was my first sign!
I ended up writing a class to abstract stuff away but the key line is, when creating the table, execute the pragma line:
PRAGMA journal_mode = OFF
http://www.stevemcarthur.co.uk/blog/post/some-kind-of-disk-io-error-occurred-sqlite/ and for more information see here http://www.sqlite.org/pragma.html
I found this was due to weird permissions with the default DELETE option. TRUNCATE works as well as OFF