Skip to content

Instantly share code, notes, and snippets.

View ljharb's full-sized avatar
🔜
working on that thing you asked about

Jordan Harband ljharb

🔜
working on that thing you asked about
View GitHub Profile

RegExp.escape(string)

Computes a new version of a String value in which certain characters have been escaped, so that the regular expression engine will interpret any metacharacters that it may contain as character literals.

When the escape function is called with one argument string, the following steps are taken:

  1. Let string be ToString(string).
  2. ReturnIfAbrupt(string).
  3. Let length be the number of characters in string.
  4. Let R be the empty string.
$ history | grep git | awk '{print $3}' | sort | uniq -c | sort -rn | head
127 st
53 dif
46 add
33 co
23 commit
16 push
12 pull
12 merge
10 br
com -bang Q q<bang>
com -bang W w<bang> <args>
com -bang WQ wq<bang> <args>
com -bang Wq wq<bang> <args>
@shinypb
shinypb / git-pr
Created December 5, 2014 17:25
Create GitHub pull request from the command line
#!/usr/bin/env ruby
remote_url = `git config --get remote.origin.url`.strip
matches = remote_url.match(/github\.com:(.+)\/(.+)\.git/)
if matches
branch_name = `git rev-parse --abbrev-ref HEAD`.strip
exec "open https://github.com/#{matches[1]}/#{matches[2]}/compare/#{branch_name}?expand=1"
end
# Save this file as ~/bin/git-pr and then `chmod +x ~/bin/git-pr`.

ES7 String trim functions

String.prototype.trim ( )

Return result of StringTrim abstract operation passing this value as thisArg, and TrimBoth as the type.

String.prototype.trimRight ( )

Return result of StringTrim abstract operation passing this value as thisArg, and TrimRight as the type.

@krohrbaugh
krohrbaugh / query_limit.rb
Created June 3, 2015 21:37
RSpec Query Limit matcher
# Allows for assertions regarding number of queries executed.
#
# Usage:
# it "eager loads `#manager` association" do
# expect do
# employee = Employee.with_manager.find(employee_id)
# employee.manager
# end.to satisfy_query_limit(1)
# end
RSpec::Matchers.define :satisfy_query_limit do |expected|
# Apple Binary Property List serializer for Ruby 1.8.
require 'iconv'
module AppleBinaryPropertyList
MIME_TYPE = 'application/octet-stream' # Don't know what to use, so use a very generic type for now
CFData = Struct.new(:data) # For marking strings as binary data which will be decoded as a CFData object
#!/usr/bin/env ruby
%w{rubygems hmac-sha1 base64 cgi net/https uri openssl}.each{ |f| require f }
KEY = '<YOUR KEY>';
SECRET = '<YOUR SECRET>';
# encodes strings that make twitter oauth happy
def encode( string )
URI.escape( string, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]") ).gsub('*', '%2A')
end
@ryanseddon
ryanseddon / fontface.css
Created February 6, 2011 23:37
The many faces of font face
// Just a bit of fun, http://www.thecssninja.com/demo/css_fontface/
// Happy face
@font-face {
font-family:InYourFace;
src: url('Ubuntu-B.eot?') format('☺'),
url('Ubuntu-B.woff') format('woff'),
url('Ubuntu-B.ttf') format('truetype'),
url('Ubuntu-B.svg#webfontssbCkuz5') format('svg');
}
@Wilto
Wilto / demo.html
Created July 3, 2012 21:06
Hide and Tel
<!DOCTYPE html>
<!--[if lt IE 7 ]> <html lang="en" class="ie ie6"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="ie ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="ie ie8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="ie ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">