Skip to content

Instantly share code, notes, and snippets.

View bingxie's full-sized avatar

Bing Xie bingxie

View GitHub Profile
@gbuesing
gbuesing / Gemfile
Last active October 28, 2020 16:01
ActiveJob with resque-scheduler on Heroku
gem 'resque-scheduler'
@brianstorti
brianstorti / priority_queue.rb
Last active November 17, 2022 16:14
Priority queue implementation in Ruby
class PriorityQueue
attr_reader :elements
def initialize
@elements = [nil]
end
def <<(element)
@elements << element
bubble_up(@elements.size - 1)
@benjie
benjie / README.md
Last active January 17, 2023 15:16
Long Live CoffeeScript and Long Live ES6

Long Live CoffeeScript and Long Live ES6

Clearly ES6 is a huge improvement over ES5, and tools like [6to5][] allow us to use these cool features now. I was reading [Replace CoffeeScript with ES6][replace coffeescript] by [Blake Williams][] and thought it was a great summary of how ES6 solves many of the same problems that CoffeeScript solves; however I'd like to comment on a few of Blake's points and talk about why I'll be sticking with CoffeeScript.

Classes

Classes in ES6 (like many of the syntax changes in ES6) are very similar to the CoffeeScript equivalent. To support browsers that are not fully ES5 compliant (e.g. IE8-), however, we still can't really use getters/setters, so ignoring these the comparison is:

@mlocher
mlocher / install_phantomjs.sh
Last active September 7, 2015 11:56
Install PhantomJS
#!/bin/bash
#
# NOTICE
# A new and updated version of this script is provided at
# https://github.com/codeship/scripts/blob/master/packages/phantomjs.sh
# Please switch to that version instead!
PHANTOMJS_VERSION="1.9.8"
# clean old version and setup directories
rm -rf ~/.phantomjs
@Chaser324
Chaser324 / GitHub-Forking.md
Last active July 22, 2024 14:45
GitHub Standard Fork & Pull Request Workflow

Whether you're trying to give back to the open source community or collaborating on your own projects, knowing how to properly fork and generate pull requests is essential. Unfortunately, it's quite easy to make mistakes or not know what you should do when you're initially learning the process. I know that I certainly had considerable initial trouble with it, and I found a lot of the information on GitHub and around the internet to be rather piecemeal and incomplete - part of the process described here, another there, common hangups in a different place, and so on.

In an attempt to coallate this information for myself and others, this short tutorial is what I've found to be fairly standard procedure for creating a fork, doing your work, issuing a pull request, and merging that pull request back into the original project.

Creating a Fork

Just head over to the GitHub page and click the "Fork" button. It's just that simple. Once you've done that, you can use your favorite git client to clone your repo or j

#Sort the Ruby files in your project by LOC
find . -iname "*.rb" -type f -exec wc -l {} \; | sort -rn
@troelskn
troelskn / install_sphinxsearch_2.1.4.sh
Created March 27, 2014 11:57
Installing sphinxsearch 2.1.4 on Ubuntu 13.10
# Install dependencies manually
apt-get install odbcinst1debian2 libodbc1 unixodbc libpq5
# Fetch deb package
mkdir -p /usr/local/build ; cd /usr/local/build && [-f sphinxsearch_2.1.4-release-0ubuntu11~precise_amd64.deb ] || wget http://sphinxsearch.com/files/sphinxsearch_2.1.4-release-0ubuntu11~precise_amd64.deb
# Install package
dpkg --install /usr/local/build/sphinxsearch_2.1.4-release-0ubuntu11~precise_amd64.deb
@jeremyfelt
jeremyfelt / open-source-search-compare.md
Last active July 19, 2023 01:28
Comparing open source search solutions
@jonwolfe
jonwolfe / gist:7897610
Created December 10, 2013 20:22
This is how we use Google Analytics with Turbolinks. I put this in a analytics.js.coffee file and require it after turbolinks. That's it. Works on browsers that support Turbolinks and those that don't. Also works with parts of your app that may not use Turbolinks. If you need to record pageviews manually for any reason, just call GoogleAnalytics…
class @GoogleAnalytics
@load: ->
# Google Analytics depends on a global _gaq array. window is the global scope.
window._gaq = []
window._gaq.push ["_setAccount", GoogleAnalytics.analyticsId()]
# Create a script element and insert it in the DOM
ga = document.createElement("script")
ga.type = "text/javascript"

Constant lookup in Ruby can happen lexically or through the ancestry tree of the receiver(a class or module). You can identify which lookup rules are being applied by the context you're in or by the syntax being used to define a class or module.

A class body that is defined as class A::B::C; …; end will lookup constants through the ancestry tree when a constant is evaluated in its class body. Anytime you see A::B::C being used as syntax to define a class or lookup the value of a constant the ancestry tree is being used for the lookup.