Skip to content

Instantly share code, notes, and snippets.

View rubendinho's full-sized avatar

Ruben Izmailyan rubendinho

View GitHub Profile
@Yaffle
Yaffle / URLUtils.js
Last active September 5, 2022 02:19
parse URL + absolutize URL in javascript (URLUtils shim - http://url.spec.whatwg.org/#url)
/*jslint regexp: true, maxerr: 50, indent: 2 */
(function (global) {
"use strict";
function URLUtils(url, baseURL) {
var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@\/?#]*)(?::([^:@\/?#]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
if (!m) {
throw new RangeError();
}
@robbyrussell
robbyrussell / ohmyzsh-dropbox-sync.sh
Created February 8, 2012 15:20
Keep your @ohmyzsh ~/.zshrc in sync via dropbox
# Was asked how I keep my zshrc config sync'd between my computers with Dropbox
# Add a new directory in your Dropbox (or use an existing one)
mkdir -p ~/Dropbox/ohmyzsh
# move existing file to Dropbox
mv ~/.zshrc ~/Dropbox/ohmyzsh/zshrc
# symlink file back to your local directory
ln -s ~/Dropbox/ohmyzsh/zshrc ~/.zshrc
@stonehippo
stonehippo / install_ruby_with_rbenv.md
Last active April 6, 2024 23:44
Installing a new Ruby with rbenv on Mac OS

Install a new Ruby with rbenv on Mac OS (and make yourself a superhero)

If you're doing stuff with Ruby on a Mac, e.g. installling Jekyll or something, by default you'll end up having to use the sudo command to do stuff, since the permission to modify the default config is not available to your user account.

This sucks and should be avoided. Here's how to fix that.

Installing a new Ruby

To make this better, we are going install a new, custom Ruby. This used to be a big, scary thing, but thanks to the awesome tools Homebrew and rbenv, it's a snap.*

A word of warning: you will have to use Terminal to install this stuff. If you are uncomfortable with text, words, and doing stuff with your computer beyond pointing and hoping, this may not work well for you. But if that's the case, I'm not sure why you were trying to use Ruby in the first place.

@mareksuscak
mareksuscak / bump-version.sh
Created March 15, 2015 12:56
Bump version shell script.
#!/bin/bash
# Thanks goes to @pete-otaqui for the initial gist:
# https://gist.github.com/pete-otaqui/4188238
#
# Original version modified by Marek Suscak
#
# works with a file called VERSION in the current directory,
# the contents of which should be a semantic version number
# such as "1.2.3" or even "1.2.3-beta+001.ab"
@ChuckJHardy
ChuckJHardy / example_activejob.rb
Last active March 3, 2024 20:10
Example ActiveJob with RSpec Tests
class MyJob < ActiveJob::Base
queue_as :urgent
rescue_from(NoResultsError) do
retry_job wait: 5.minutes, queue: :default
end
def perform(*args)
MyService.call(*args)
end
@kgriffs
kgriffs / uuid_regex.py
Last active September 28, 2023 19:03
UUID regular expressions (regex) with usage examples in Python
import re
# RFC 4122 states that the characters should be output as lowercase, but
# that input is case-insensitive. When validating input strings,
# include re.I or re.IGNORECASE per below:
def _create_pattern(version):
return re.compile(
(
'[a-f0-9]{8}-' +
@dansteele
dansteele / create_review_app_subdomain.rake
Last active September 15, 2022 23:45
Use a sub-subdomain on Heroku review apps with DNSimple. Run this task from your app.json in your postdeploy script.
namespace :staging do
desc 'create subdomain DNS record for Heroku review app'
task :publish_dns do
require 'dnsimple'
require 'platform-api'
STAGING_DOMAIN = 'mystagingdomain.com'.freeze
DNSIMPLE_ACCOUNT_ID = .freeze
heroku_app_name = ENV['HEROKU_APP_NAME']
subdomain = heroku_app_name.match(/.*(pr-\d+)/).captures.first
require 'spec_helper'
describe 'GraphQL acceptance' do
describe 'allLinks' do
it 'returns all links' do
link1 = create :link, description: 'first'
link2 = create :link, description: 'second'
query = %(
{
@hopsoft
hopsoft / prefetch.js
Last active December 27, 2023 02:45
Turbolinks Prefetching
const hoverTime = 400
const fetchers = {}
const doc = document.implementation.createHTMLDocument('prefetch')
function fetchPage (url, success) {
const xhr = new XMLHttpRequest()
xhr.open('GET', url)
xhr.setRequestHeader('VND.PREFETCH', 'true')
xhr.setRequestHeader('Accept', 'text/html')
xhr.onreadystatechange = () => {