Skip to content

Instantly share code, notes, and snippets.

View kofronpi's full-sized avatar

Pierre-Alexandre Kofron kofronpi

View GitHub Profile
@clyfe
clyfe / optimized_pdfkit.rb
Created November 1, 2011 11:06
An optimized version of pdfkit, with a slightly more involved interface
# Usage
#
# OptimizedPDFKit.new(html_tempfile).to_pdf(pdf_tempfile_path)
#
class OptimizedPDFKit < PDFKit
def initialize(url_file_or_html, options = {})
@source = Source.new(url_file_or_html)
@stylesheets = []
@rstacruz
rstacruz / index.md
Last active November 3, 2023 09:56
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

@mourner
mourner / TileLayer.Common.js
Created February 11, 2012 23:11
Leaflet shortcuts for common tile providers
// Lefalet shortcuts for common tile providers - is it worth adding such 1.5kb to Leaflet core?
L.TileLayer.Common = L.TileLayer.extend({
initialize: function (options) {
L.TileLayer.prototype.initialize.call(this, this.url, options);
}
});
(function () {
@daviferreira
daviferreira / smooth-scrolling.coffee
Created March 31, 2012 23:46
Smooth scrolling for anchor '#' links using jQuery and CoffeeScript
# based on http://www.paulund.co.uk/smooth-scroll-to-internal-links-with-jquery
$ ->
$('a[href^="#"]').on 'click.smoothscroll', (e) ->
e.preventDefault()
target = @hash
$target = $(target)
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active July 22, 2024 09:57
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@mattconnolly
mattconnolly / gist:4158961
Created November 28, 2012 04:04
RSpec basic authentication helper module for request and controller specs
module AuthHelper
def http_login
user = 'username'
pw = 'password'
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user,pw)
end
end
module AuthRequestHelper
#
@cobyism
cobyism / gh-pages-deploy.md
Last active July 18, 2024 05:22
Deploy to `gh-pages` from a `dist` folder on the master branch. Useful for use with [yeoman](http://yeoman.io).

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

For the sake of this example, let’s pretend the subfolder containing your site is named dist.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).

@ghuntley
ghuntley / get-all-markers-on-map-get-all-polygons-on-map-find-which-markers-are-within-a-polygon.js
Created February 26, 2013 05:29
Example of one way to integrate Leafletjs w/ Leaflet.draw extending it to add methods to: - Load markers from KML and overlay onto map. - Return array of all markers on a map. - Return array of all polygons on a map. - Return array of markers which are within a specified polygon. Requires UnderscoreJS and @shramov/leaflet-plugins (for KML loader…
// <summary>
// Logging methods.
// </summary>
Log = {
Dump: function (object)
{
if (object)
{
console.debug(object);
}
@jakeonrails
jakeonrails / migrating.md
Last active May 28, 2019 21:38
Migrating from Postgres 9.0/Postgis 1.5 to Postgres 9.2/Postgis 2.0 on Heroku

Migrating from Postgres 9.0/Postgis 1.5 to Postgres 9.2/Postgis 2.0 on Heroku

This may not be relevant to many, but it's a process that I just had to go through and it was a bit tricky to figure a smooth way to make it work.

The gist of it is that you must do the following:

  • Export your production database from heroku to your local machine
  • Create a new, blank database with Postgres 9.2 and PostGIS 2.0
  • Import your heroku database into the new local database running 9.2/2.0
  • Dump the new database and upload it to S3
@jboesch
jboesch / pg_import_csv_to_heroku.sh
Last active April 5, 2022 22:11
Importing a CSV dump of Postgres data into Heroku
# You have your csv data and it looks like so... It's in a file named "my_data.csv" and we want to import it into a table named "my_things".
"1", "Something", "0.50", "2013-05-05 10:00:00"
"2", "Another thing", "1.50", "2013-06-05 10:30:00"
# Now you want to import it, go to the command line and type:
$ PGPASSWORD=PWHERE psql -h HOSTHERE -U USERHERE DBNAMEHERE -c "\copy my_things FROM 'my_data.csv' WITH CSV;"
# Voila! It's impoted. Now if you want to wipe it out and import a fresh one, you would do this: