Skip to content

Instantly share code, notes, and snippets.

View acorcutt's full-sized avatar
Making Stuff

Anthony Corcutt acorcutt

Making Stuff
View GitHub Profile
@busypeoples
busypeoples / validateSpec.js
Last active September 27, 2017 18:08
Validate deeply nested inputs.
const R = require('ramda')
const colors = ['green', 'blue', 'red']
const notEmpty = R.compose(R.not, R.isEmpty)
const minLength = a => b => R.length(b) > a
const hasPresetColors = x => R.indexOf(x, colors) !== -1
const input = {
id: 1,
userName: 'Random',
@acorcutt
acorcutt / Cloud9GithubOrg
Created April 13, 2017 20:52
Allow Cloud9 to push to org repo
To allow c9 workspace to push to github org repository you must allow it in 3rd party access setup https://github.com/organizations/<org>/settings/oauth_application_policy
Either remove restrictions or allow it from your https://github.com/settings/applications
@chrisveness
chrisveness / crypto-pbkdf2.js
Last active December 21, 2023 19:20
Uses the SubtleCrypto interface of the Web Cryptography API to hash a password using PBKDF2, and validate a stored password hash against a subsequently supplied password. Note that both bcrypt and scrypt offer better defence against ASIC/GPU attacks, but are not available within WebCrypto.
/**
* Returns PBKDF2 derived key from supplied password.
*
* Stored key can subsequently be used to verify that a password matches the original password used
* to derive the key, using pbkdf2Verify().
*
* @param {String} password - Password to be hashed using key derivation function.
* @param {Number} [iterations=1e6] - Number of iterations of HMAC function to apply.
* @returns {String} Derived key as base64 string.
*
@chrisross
chrisross / gcd_sass_script.scss
Last active February 23, 2023 23:27
This Sass (SCSS) function utilises the Greated Common Divisor (gcd) to reduce duplicate styles.
// Algorithm to calculate the Lowest Common Denominator
@function gcd($a, $b){
@if $b == 0 {
@return $a;
} @else {
@return gcd($b, $a%$b);
}
}
// Example Use-case:
@afeld
afeld / gist:5704079
Last active November 27, 2023 15:43
Using Rails+Bower on Heroku
@Protonk
Protonk / prng.js
Last active April 7, 2023 09:30
Various PRNGs, implemented in javascript.
// Linear Congruential Generator
// Variant of a Lehman Generator
var lcg = (function() {
// Set to values from http://en.wikipedia.org/wiki/Numerical_Recipes
// m is basically chosen to be large (as it is the max period)
// and for its relationships to a and c
var m = 4294967296,
// a - 1 should be divisible by m's prime factors
a = 1664525,
// c and m should be co-prime
@cobyism
cobyism / gh-pages-deploy.md
Last active July 5, 2024 05:07
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).

@elutz
elutz / controller.js
Created November 27, 2012 08:56
File Upload with AngularJS & File-Upload jQuery Plugin
function AttachmentCtrl($scope, $location, $timeout, Docs) {
$(function() {
$('#detail-form-doc').fileupload({
dataType: 'json',
url: '/angular-ib/app/fileupload?id=' + $location.search().id,
add: function(e, data) {
$scope.$apply(function(scope) {
// Turn the FileList object into an Array
for (var i = 0; i < data.files.length; i++) {
$scope.project.files.push(data.files[i]);
@kazpsp
kazpsp / passwords_controller.rb
Created August 14, 2012 16:40 — forked from guilleiguaran/passwords_controller.rb
StrongParameters with Devise
# app/controllers/users/password_controller.rb
class Users::PasswordsController < Devise::PasswordsController
def resource_params
params.require(:user).permit(:email, :password, :password_confirmation)
end
private :resource_params
end
@danshultz
danshultz / liquid_view.rb
Created June 12, 2012 03:11
liquid/lib/extras/liquid_view.rb file to use in Rails 3 with layouts
# LiquidView is a action view extension class. You can register it with rails
# and use liquid as an template system for .liquid files
#
# Example
#
# ActionView::Base::register_template_handler :liquid, LiquidView
class LiquidView
PROTECTED_ASSIGNS = %w( template_root response _session template_class action_name request_origin session template
_response url _request _cookies variables_added _flash params _headers request cookies
ignore_missing_templates flash _params logger before_filter_chain_aborted headers )