Skip to content

Instantly share code, notes, and snippets.

View fercreek's full-sized avatar
😎
Coding coding coding

Fernando Contreras fercreek

😎
Coding coding coding
View GitHub Profile
@diemol
diemol / chromedriver-install.sh
Last active July 9, 2021 15:03
Geckodriver and Chromedriver installers for OSX/Mac
#!/bin/bash
# download and install latest chromedriver for linux or mac.
# required for selenium to drive a Chrome browser.
install_dir="/usr/local/bin"
version=$(wget -qO- https://chromedriver.storage.googleapis.com/LATEST_RELEASE)
if [[ $(uname) == "Darwin" ]]; then
url=https://chromedriver.storage.googleapis.com/$version/chromedriver_mac64.zip
elif [[ $(uname) == "Linux" ]]; then
url=https://chromedriver.storage.googleapis.com/$version/chromedriver_linux64.zip
@tobiashm
tobiashm / README.md
Created August 30, 2017 08:02
Use PhantomJS to render PDF in Rails

Use PhantomJS to render PDF in Rails

Avoid disk IO

If you're deploying your app to somewhere where you can't be sure to have reliable disk read/write access, the normal strategy of writing to a temp-file doesn't work. Instead we can open a pipe to the Phantom.js process, and then pass in the HTML via stdin, and then have the rasterize.js script write out the resulting PDF to stdout, which we can then capture. Any log messages from the Phantom.js process can be passed via stderr if we want.

Session heist

@cgoldberg
cgoldberg / geckodriver-install.sh
Last active August 18, 2023 10:20
download and install latest geckodriver for linux or mac (selenium webdriver)
#!/bin/bash
# download and install latest geckodriver for linux or mac.
# required for selenium to drive a firefox browser.
install_dir="/usr/local/bin"
json=$(curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest)
if [[ $(uname) == "Darwin" ]]; then
url=$(echo "$json" | jq -r '.assets[].browser_download_url | select(contains("macos"))')
elif [[ $(uname) == "Linux" ]]; then
url=$(echo "$json" | jq -r '.assets[].browser_download_url | select(contains("linux64"))')
@mikermcneil
mikermcneil / sails-policy-best-practices-and-faq.md
Last active July 11, 2019 09:48
FAQ and best practices for using policies in Sails.js

Policies in Sails.js

Policies are additive. Anything you might do with policies, you could just implement in your custom actions directly. But they can make your life a lot easier.

When should I use policies?

Policies can be used like middleware, meaning you can do almost anything you can imagine with them. That said, our experience using Sails to build all sorts of different apps has taught us that policies are best used for one, very specific purpose: preventing access to actions for certain users (or types of users) where those actions are not accessible in the UI. That is, policies are best used like preconditions-- you can use them to take care of edge cases that are only possible by cheating the UI.

For example, imagine you're building an action called changePassword in your UserController. Its job is to take the new password that was provided, encrypt it, then update the database record for the currently-logged-in user to save the new encryped password. When you implement and test

@PurpleBooth
PurpleBooth / README-Template.md
Last active July 27, 2024 07:37
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@arjunvenkat
arjunvenkat / gist:1115bc41bf395a162084
Last active January 12, 2024 05:04
Seeding a Rails database with a CSV file

How to seed a Rails database with a CSV file

1. Setup

First, Create a folder inside of lib called seeds

Put your CSV file example.csv into the lib/seeds folder. In the example below, the file is called real_estate_transactions.csv

Make sure you've created a resource with the appropriate columns to match your seed data. The names don't have to match up.

@danharper
danharper / gulpfile.js
Last active April 11, 2024 08:31
New ES6 project with Babel, Browserify & Gulp
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var babel = require('babelify');
function compile(watch) {
var bundler = watchify(browserify('./src/index.js', { debug: true }).transform(babel));
require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
describe "GET #index" do
#describe "POST #create" do
#describe "GET #show" do
#describe "PATCH #update" do (or PUT #update)
#describe "DELETE #destroy" do
#describe "GET #new" do
@toddmotto
toddmotto / listeners.js
Last active September 14, 2016 04:59
Automatic unbinding on $scope.$destroy for $rootScope listeners
/*!
* $rootScope listeners, remember to unbind on $destroy
*/
var $rootListeners = {
'transmitProgress': $rootScope.$on('transmit:progress', transmitProgress),
'transmitSuccess': $rootScope.$on('transmit:success', transmitSuccess),
'transmitError': $rootScope.$on('transmit:error', transmitError)
};
// iterate the Object and pass the methods to be called on $destroy