Skip to content

Instantly share code, notes, and snippets.

@SylarRuby
SylarRuby / downloads_controller.rb
Last active August 25, 2022 06:43
Loop through all, zip and download from ActiveStorage
# In our gemfile:
# gem 'rubyzip'
require 'zip'
# private ?
def process_and_create_zip_file
# Simulation of an object with has_many_attached :documents
job = Job.first.documents
# Tmp folder to store the download files from S3
@steipete
steipete / ios-xcode-device-support.sh
Last active December 12, 2023 03:36
Using iOS 15 devices with Xcode 12.5 (instead of Xcode 13)
# The trick is to link the DeviceSupport folder from the beta to the stable version.
# sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :)
# Support iOS 15 devices (Xcode 13.0) with Xcode 12.5:
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/15.0 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
# Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions
# (A similar approach works for older versions too, just change the version number after DeviceSupport)
# Elm Sprockets Integration for Rails 3
#
# I'm working on turning this into a Gem - see https://github.com/NoRedInk/sprockets-elm - but
# I know a lot more about Elm than I do Rails, and haven't gotten that version working yet.
# If you know how to help Gemify this, by all means please hit me up! https://twitter.com/rtfeldman
# I could definitely use the help.
#
# Anyway, in the meantime, this is what we're using at NoRedInk to integrate Elm into our asset
# pipeline, and it works like a charm. Just copy this into config/initializers/elm_sprockets.rb
#
To circle.yml:
dependencies:
post:
- bin/cisetup
checkout:
post:
- git fetch origin --depth=1000000
@NikoWoot
NikoWoot / reduce-size.dockerimage
Created December 19, 2014 08:37
Reduce size of Docker image
=================================================
After software installation
=================================================
RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
=================================================
Docker on build process, include all files on directory build (include .git with old build)
Solution for reduce size of docker image (but for reuse is not good solution)
=================================================
@sudara
sudara / Github-style-syntax-in-pages.md
Last active December 31, 2020 02:49
Github style syntax highlighting in Pages.app

I like Pages.app, but don't want to deal with constantly copying and pasting code around.

Here is how I do syntax highlighting in Pages.app by pressing a key command. It's based off of this post on stack exchange.

install pygments

sudo easy_install Pygments

install github syntax

@romansklenar
romansklenar / crosstab.sql
Last active February 1, 2023 18:46
PostgreSQL "pivot table" example using tablefunc extension
CREATE EXTENSION tablefunc;
CREATE TABLE sales(year int, month int, qty int);
INSERT INTO sales VALUES(2007, 1, 1000);
INSERT INTO sales VALUES(2007, 2, 1500);
INSERT INTO sales VALUES(2007, 7, 500);
INSERT INTO sales VALUES(2007, 11, 1500);
INSERT INTO sales VALUES(2007, 12, 2000);
INSERT INTO sales VALUES(2008, 1, 1000);
INSERT INTO sales VALUES(2009, 5, 2500);
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<link type="text/css" rel="stylesheet" href="style.css"/>
<script src="http://d3js.org/d3.v3.min.js"></script>
<style>
.node circle {
cursor: pointer;
fill: #fff;
@andkerosine
andkerosine / raskell.rb
Created August 15, 2012 05:56
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@

Proposal for Improving Mass Assignment

For a while, I have felt that the following is the correct way to improve the mass assignment problem without increasing the burden on new users. Now that the problem with the Rails default has been brought up again, it's a good time to revisit it.

Sign Allowed Fields

When creating a form with form_for, include a signed token including all of the fields that were created at form creation time. Only these fields are allowed.

To allow new known fields to be added via JS, we could add: