Skip to content

Instantly share code, notes, and snippets.

View zackfern's full-sized avatar
:dependabot:
Every bot wants to rule the world

Zack Fernandes zackfern

:dependabot:
Every bot wants to rule the world
View GitHub Profile
@zackfern
zackfern / time_formats.rb
Created April 1, 2024 00:39
Some date formats I regularly find myself using in my Rails projects
Time::DATE_FORMATS[:ymd] = "%F" # 2023-01-01
Time::DATE_FORMATS[:mdy] = "%D" # 01/01/23
Time::DATE_FORMATS[:human] = "%B %d, %Y" # January 01, 2023
Time::DATE_FORMATS[:time_12] = "%I:%M %p" # 01:30 PM
@zackfern
zackfern / join_playing_sonos.yaml
Created April 28, 2023 22:07
A Home Assistant script to make a Sonos speaker join whichever speaker is currently playing
# Add this to your scripts.yaml file
join_playing_sonos:
description: "Make a Sonos spaker join whichever speaker is current playing."
fields:
target:
description: "Entity ID of the Sonos which you'd like to make join the group"
example: "media_player.office"
variables:
group_owner: '{{ state_attr((integration_entities("sonos") | select("is_state", "playing") | first), "group_members") | first }}'
@zackfern
zackfern / merged.sh
Created May 16, 2017 17:50
merged function for easily telling if a Git branch has been merged into the current branch
merged () {
CURRENT=`git rev-parse --abbrev-ref HEAD`;
if git merge-base --is-ancestor $1 $CURRENT; then
echo "\e[32m$1 is merged into $CURRENT"
else
echo "\e[31m$1 is NOT merged into $CURRENT"
fi
}
@zackfern
zackfern / patched.sh
Last active August 29, 2015 14:01
Ruby 1.9.3-p125-pref Fix
build_package_combined_patch() {
local package_name="$1"
{
curl https://github.com/ruby/ruby/pull/47.diff | git apply
curl https://gist.githubusercontent.com/zackfern/45914b53db7720146899/raw/cda389aaca50685f6f5f8496b0aa99b73dd4fa3b/performance_and_backport_gc.patch | patch -p1
autoconf
./configure --prefix="$PREFIX_PATH" $CONFIGURE_OPTS
make -j 8
make install
@zackfern
zackfern / parse_date_select_values.rb
Created October 22, 2013 02:02
Helper method for parsing the output from date_select fields.
# Public: Parse values from Rails date_select form helper.
#
# dsv - Stands for Date Select Values. Pass in whatever hash
# contains the attributes of the date_select box.
# name - Name of the Date Select. For example, if your params
# contain 'date_of_birth(2i)' then your name would be
# 'date_of_birth' (which happens to be the default)
#
# Returns a Date object.
def parse_date_select_values(dsv, name='date_of_birth')

Sublime to Vim

  • Use Control+W instead of Alt+Backspace
  • To unindent a line, use Ctrl+D
  • To indent a line, use Ctrl+T
  • Upper-case J joins lines (same as Cmd+J in Sublime Text)
  • Use :edit! to force a reload of the current file from disk.
  • To skip to the first non-whitespace character on a line, press ^
  • yy copies (yanks) a line

Window Commands

@zackfern
zackfern / lastfm_now_playing.js
Last active April 16, 2024 15:16
Displays your latest last.fm tracks on your webpage.
// Hacky last.fm Now Playing
// by Zack Fernandes (zackfern.me) April 2013
//
// Instructions:
// - Install jQuery, if you don't have it already.
// - Create a last.fm API key and set the api_key variable.
// - Set the username variable to your last.fm username.
// - Add something with the ID of now_playing in your site.
// - Include this script and enjoy.
//
@zackfern
zackfern / latest_preserve_bookmarks.js
Created April 22, 2013 20:17
Display your latest Preserve bookmarks on your personal website!
$(function(){
// Loading the latest profile JSON from Preserve.
$.getJSON('http://preserve.io/u/zackfern.json', function(data){
var items = [];
// How many bookmarks are we going to display?
var limit = 4;
var bookmarks = 0;
$.each(data.user.bookmarks, function(key, bookmark){
if(bookmarks > limit) {
return false;
#!/usr/bin/ruby
#
# README
# This is a simple script to upload files to Amazon S3.
# Configuration is provided below for your S3 credentials, bucket to upload to, path to upload to, and base URL.
# When the script is finished, it will output the base URL followed by the path and uploaded file name.
# The script can rename files if USE_ORIGINAL_FILE_NAME is set to false.
# By default, it will name the file based off the current date and time (for example, 2013-03-03-153427.png).
#
# Once you've configured the script, simply pass the script the path to your file.
curl -X POST "http://localhost:9200/dashboard/_search?pretty=true" -d '
{
"query" : { "match_all" : {} },
"facets" : {
"tags" : { "terms" : {"field" : "tags", "size" : 10} }
}
}
'