Skip to content

Instantly share code, notes, and snippets.

@fiveNinePlusR
fiveNinePlusR / Rails Controller.md
Created March 11, 2024 00:59 — forked from stevenyap/Rails Controller.md
Rails controller cheatsheet

Flash

# supports only notice and alert by default
# the rest has to go into flash hash
redirect_to :index, notice: "success"
redirect_to :new, notice: "errors"
redirect_to :new, flash: { success: "yeah" }
flash[:info] = "updated"
@fiveNinePlusR
fiveNinePlusR / backup_current_folder.rb
Created July 19, 2022 00:28
quick script to backup the current folder using ruby with a blacklist
#! /usr/bin/env ruby
directory = Dir.getwd.split("/").pop
command = "tar czf ../#{directory}-#{Time.now.strftime("%Y-%m-%d-%H%M%S")}.tar.gz ."
blacklist = %W[usr Users #{ENV["USER"]} projects]
blacklist << nil
if blacklist.include? directory
puts "Forbidden directory"
puts "Command if you want to run it manually: #{command}"
@fiveNinePlusR
fiveNinePlusR / jSugar.js
Created May 19, 2022 18:42 — forked from pseudosavant/jSugar.js
Utility function that adds in some jQuery-like syntactic sugar
// jQuery-like syntactic sugar. Only queries for one element. Does not loop over multiple like jQuery
function $(query) {
if (typeof query === 'undefined') throw 'No query provided to $';
var el;
if (typeof query.nodeType === 'string') {
el = query;
} else if (typeof query === 'string' && query[0] === '<') {
const container = document.createElement('div');
container.innerHTML = query;
@fiveNinePlusR
fiveNinePlusR / NSScanner+Swift.swift
Last active December 3, 2018 21:56 — forked from natecook1000/NSScanner+Swift.swift
Swift-friendly NSScanner methods updated for swift 4.2
// NSScanner+Swift.swift
// A set of Swift-idiomatic methods for NSScanner
//
// (c) 2015 Nate Cook, licensed under the MIT license
import Foundation
extension Scanner {
// MARK: Strings
// NSScanner+Swift.swift
// A set of Swift-idiomatic methods for NSScanner
//
// (c) 2015 Nate Cook, licensed under the MIT license
import Foundation
extension Scanner {
// MARK: Strings
require 'open3'
#basic shell command
def run_command(current_command)
Open3.popen2e(current_command) {|stdin, stdout, wait_thr|
pid = wait_thr.pid # pid of the started process.
puts pid
stdout.each do |line| log line end