Skip to content

Instantly share code, notes, and snippets.

View zackfern's full-sized avatar
🌭

Zack Fernandes zackfern

🌭
View GitHub Profile
@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 / 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 / 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 / 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} }
}
}
'
@zackfern
zackfern / state_list_helper.rb
Created June 3, 2012 23:28
Rails State List Helper
# Public: Returns an Array of States (for use in Select Tags)
#
# short - (bool) If you want the function to return State Abreviations or full state names.
#
# Returns array.
def state_list(short=false)
if short
return ['AL','AK','AZ','AR','CA','CO','CT','DE','FL','GA','HI','ID','IL','IN','IA','KS','KY','LA','ME','MD','MA','MI','MN','MS','MO','MT','NE','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VT','VA','WA','WV','WI','WY']
else
return ['Alabama','Alaska','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','Florida','Georgia','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Ohio','Oklahoma','Oregon','Pennsylvania','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virginia','Wash