Skip to content

Instantly share code, notes, and snippets.

View alanhogan's full-sized avatar

Alan Hogan alanhogan

View GitHub Profile
@alanhogan
alanhogan / failon.sh
Created May 5, 2022 15:44
Fail on pattern match of output while showing output. zsh + macOS compatible
# Allow failing on regex pattern match
# See https://superuser.com/a/1717757/60337
failon() (
pattern="$1"
shift
[ "$#" -eq 0 ] && set cat
FAILON_STATUS="${FAILON_STATUS:-125}"
set -o pipefail
{ "$@" \
| "$@" >&3 \
@alanhogan
alanhogan / remove-scss-files.rb
Created October 26, 2018 23:58
Very good Ruby broh
#!/usr/bin/env ruby
require 'find'
puts "Deleting all .scss files !!!! !!11"
deleted = 0
Find.find('.') do |path|
if FileTest.directory?(path)
@alanhogan
alanhogan / sass-filenames-to-comments.rb
Created October 26, 2018 23:56
Convert // comments to /* */ (for .scss files)
#!/usr/bin/env ruby
require 'find'
puts "Yo dawg, i only work on .scss files, not .sass. just a warning."
nonMatchingFiles = 0
def fileContents(filename)
data = ''
@alanhogan
alanhogan / safari_cant_find_the_server.html
Created May 26, 2018 01:41
Interesting HTML for a Safari error page
<!-- LOCALIZERS: Each localizable piece of the page is marked with a comment -->
<html>
<head>
<link rel=stylesheet type="text/css" href="page-load-errors.css">
<!-- LOCALIZERS: You might want to change the font family. You can also add styles to override sizes, etc. -->
<style>
body {font-family:'-apple-system-font';}
</style>
<!-- LOCALIZERS: The next line contains the page title that appears in the window's title bar -->
<title>Failed to open page</title>

Keybase proof

I hereby claim:

  • I am alanhogan on github.
  • I am alanhogan (https://keybase.io/alanhogan) on keybase.
  • I have a public key ASBsuC4ft6MgMV-UB77lHthuXxHIhQhvcYqMt_RY1Sl70go

To claim this, I am signing this object:

payWithTweet is a jQuery plugin that makes you go tweet something to unlock an action on the page. You can bypass it by running:

function createCookie(name,value,days){var expires;if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));expires="; expires="+ date.toGMTString();}else{expires="";}
document.cookie=encodeURIComponent(name)+"="+ encodeURIComponent(value)+ expires+"; path=/";}

createCookie("tweetToDownload",true,30);

npm shrinkwrap is useful, but maddening (once it's in place and you want to update a package).

Say you've got a package.json with module ember-cli as a devDependency currently at version 1.13.1. And you have an npm-shrinkwrap.json file too, generated with the --dev flag.

If you change the version of ember-cli to, say, 1.13.8 in package.json and run npm install, nothing will happen.

If you do that and manually change references in the shrinkwrap file, you will still have trouble (as nested dependencies may now be incorrect).

So what do we actually do?

$four: "4";
$seven: "7";
$pi: 3.14159;
$phi: 1.618;
$null: null;
@if $seven > $four { // may only compare numbers on line 2 at column 9
.fourIsBiggerThanSeven {
color: green;
}
@alanhogan
alanhogan / autoselect.coffee
Created August 26, 2014 00:39
CoffeeScript Require.js Module for jQuery-based element selection on click
$ = require 'jquery'
module.exports = do ->
init = ->
$(document).on 'click', '.js-autoselect', (e) ->
range = document.createRange()
selection = window.getSelection()
range.selectNodeContents this

Here are some of the "gotchas" I've encountered when I converted all the javascript code into coffeescript. (BTW, this is gathered while coding for YourMechanic.com, a very cool mobile auto repair service.)

Disclaimer: Coffeescript is a great productivity booster for me personally. Even with all the things outlined below, it is still way better than javascript. None of these should discourage you from jumping into it right away.

Major gotchas

(Things that generate wrong code silently)