Skip to content

Instantly share code, notes, and snippets.

View sunny's full-sized avatar
☀️

Sunny Ripert sunny

☀️
View GitHub Profile
@sunny
sunny / add_frozen_string_literal_comment.rb
Last active November 23, 2022 17:03 — forked from ta1kt0me/add_frozen_string_literal_comment.rb
Add frozen string literal comment into generated files in Rails 7
# frozen_string_literal: true
# Via https://gist.github.com/ta1kt0me/6a7058d16621785d4f7038bde6cd3b98
module RailsGeneratorFrozenStringLiteralPrepend
RUBY_EXTENSIONS = %w[.rb .rake].freeze
def render
return super unless RUBY_EXTENSIONS.include?(File.extname(destination))
"# frozen_string_literal: true\n\n#{super}"
@sunny
sunny / git-checkout.rake
Last active August 19, 2022 10:04 — forked from skyriverbend/rails_switch_branch.py
Task to checkout a branch in rails and apply or rollback the migrations between the two.
# encoding: UTF-8
#
# $ rake checkout new_branch_name
#
# Via https://gist.github.com/jonlemmon/4076864
#
# 1. Roll back any migrations on your current branch which do not exist on the
# other branch
# 2. Discard any changes to the db/schema.rb file
# 3. Check out the other branch
@sunny
sunny / sunnytize.php
Created December 7, 2011 10:14 — forked from LanF3usT/sunnytize.php
WordPress plugin that removes evil characters in file names
<?php
/*
Plugin Name: Sunnytize
Plugin URI:
Description: A better file name sanitizer
Version: 2.0
Author: Sunny Ripert, Bastien Maillard, Guillaume Morisseau
Author URI: http://sunfox.org
*/
@sunny
sunny / gist:75417
Created March 7, 2009 19:41 — forked from NaPs/gist:73981
#!/usr/bin/env python2.6
#
# Riff, rock, and much more !!
#
# Copyright 2008 Antoine Millet <antoine@inaps.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
@sunny
sunny / gist:53587
Created January 27, 2009 21:52 — forked from sr/gist:53511
@sunny
sunny / gist:25917
Created November 17, 2008 21:38 — forked from sr/gist:25914
#!/usr/bin/env ruby
class String
def truncate(length = 30, truncate_string = "...")
return self if self.length <= length
short_length = length - truncate_string.length
self[0...short_length] + truncate_string
end
end
def date
# The infamous Monkey-Hash. Example:
# h = {}
# h.foo = "bar"
# h.foo # => "bar"
class Hash
def method_missing(method, *params)
key = method.to_s
if key =~ /=$/
key = key[0..-2]
# irb(main):001:0> h = {}
# => {}
# irb(main):002:0> h.foo = "bar"
# => "bar"
# irb(main):003:0> h.foo
# => "bar"
class Hash
def method_missing(method, *params)
method_string = method.to_s
@sunny
sunny / sniffarp.py
Created September 20, 2008 13:17 — forked from NaPs/sniffarp.py
#!/usr/bin/env python
# Written by Antoine 'NaPs' Millet
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2004 Sam Hocevar
# 14 rue de Plaisance, 75014 Paris, France
# Everyone is permitted to copy and distribute verbatim or modified
function is-git? {
git status &> /dev/null
[ $? != 128 ]
}
function git-init-remote {
name=$(basename $PWD).git
path=~/repositories/$name
if is-git?; then
ssh bearnaise.net -t "mkdir $path && cd $path && git --bare init" ||