Skip to content

Instantly share code, notes, and snippets.

View kwent's full-sized avatar
🏠
Working from home

Quentin Rousseau kwent

🏠
Working from home
View GitHub Profile
@kwent
kwent / 20200119064500_add_position_column_to_active_storage_attachments.rb
Last active February 3, 2024 16:25
Rails | Active Storage Attachment + acts_as_list
# db/migrate/20200119064500_add_position_column_to_active_storage_attachments.rb
class AddPositionColumnToActiveStorageAttachments < ActiveRecord::Migration[6.0]
def change
add_column :active_storage_attachments, :position, :integer, default: 0
end
end
public class AnimatedActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//opening transition animations
overridePendingTransition(R.anim.activity_open_translate,R.anim.activity_close_scale);
}
@kwent
kwent / cancelable.rb
Created December 30, 2018 23:17
Cancelable Rails concern
module Cancelable
extend ActiveSupport::Concern
included do
scope :with_cancelled, -> { where.not(cancelled_at: nil) }
scope :not_cancelled, -> { where(cancelled_at: nil) }
def cancel
# Use update_attributes and not touch to trigger after_save
@kwent
kwent / sftp.rb
Last active April 14, 2021 14:45
Create a ruby pseudo terminal (PTY) and invoke an interactive command (SFTP)
require 'pty'
require 'expect'
PTY.spawn('sftp username@sftp.domain.com:/uploads') do |input, output|
# Say yes to SSH fingerprint
input.expect(/fingerprint/, 2) do |r|
output.puts "yes" if !r.nil?
@kwent
kwent / rails_test.yml
Created November 11, 2020 09:14
Rails Test GitHub Action
name: Rails Tests
on:
pull_request:
git difnches:
- "master"
push:
branches:
- "master"
@kwent
kwent / CupertinoPageRoute.dart
Last active January 22, 2020 00:54
CupertinoPageRoute.dart | Animation left to right
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:math';
import 'dart:ui' show lerpDouble, ImageFilter;
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
@kwent
kwent / backup_neo4j_to_s3.sh
Last active November 27, 2019 05:38
NEO4J Backup to AWS S3 Shell Script
#!/bin/sh -
#title :backup_neo4j_to_s3.sh
#description :This script is creating a NEO4J Backup through neo4j-backup tool,
# compress the backup folder via LZMA2 algorithm compression, and upload it to AWS S3.
#author :Quentin Rousseau <contact@quent.in>
#date :2014-07-28
#version :1.1
#usage :sh backup_neo4j_to_s3.sh ip port destination | eg. sh backup_neo4j_to_s3.sh 127.0.0.1 6362 /mnt/datadisk/backup
#dependencies :apt-get update && apt-get install p7zip-full && apt-get install awscli.
#==============================================================================
# config/initializers/activestorage.rb
Rails.application.config.to_prepare do
# Provides the class-level DSL for declaring that an Active Record model has attached blobs.
ActiveStorage::Attached::Macros.module_eval do
def has_one_attached(name, dependent: :purge_later, acl: :private)
class_eval <<-CODE, __FILE__, __LINE__ + 1
def #{name}
@active_storage_attached_#{name} ||= ActiveStorage::Attached::One.new("#{name}", self, dependent: #{dependent == :purge_later ? ":purge_later" : "false"}, acl: "#{acl}")
end
@kwent
kwent / kubernetes_deis_local.md
Last active March 15, 2017 22:35 — forked from kerin/kubernetes_deis_local.md
Local Kubernetes/Deis environment
@kwent
kwent / exit_code.bash
Created March 9, 2016 01:05
Echo command exit code
#!/bin/bash
set -o errexit # Always use `errexit`
run_the_cmd && code=$? || code=$?
echo "The exit code was: $code" >&2