Skip to content

Instantly share code, notes, and snippets.

View dinks's full-sized avatar

Dinesh Vasudevan dinks

View GitHub Profile
@atoponce
atoponce / gist:07d8d4c833873be2f68c34f9afc5a78a
Last active September 7, 2024 18:11 — forked from tqbf/gist:be58d2d39690c3b366ad
Cryptographic Best Practices

Cryptographic Best Practices

Putting cryptographic primitives together is a lot like putting a jigsaw puzzle together, where all the pieces are cut exactly the same way, but there is only one correct solution. Thankfully, there are some projects out there that are working hard to make sure developers are getting it right.

The following advice comes from years of research from leading security researchers, developers, and cryptographers. This Gist was [forked from Thomas Ptacek's Gist][1] to be more readable. Additions have been added from

# Has your OS/FS/disk lost your data?
# cd to the directory containing your project repositories and run the command
# below. (It's long; make sure you get it all.) It finds all of your git repos
# and runs paranoid fscks in them to check their integrity.
(set -e && find . -type d -and -iname '.git' | while read p; do (cd "$(dirname "$p")" && (set -x && git fsck --full --strict)); done) && echo "OK"
# I have 81 git repos in my ~/proj directory and had no errors.
@jussi-kalliokoski
jussi-kalliokoski / draw-waveform.js
Created September 24, 2014 06:41
Waveform drawing
function getAudioData (url, time) {
return new Promise(function (resolve, reject) {
var context = new AudioContext();
var track = new Audio(url);
var bufferLength = time * context.sampleRate;
var buffer = new Float32Array(bufferLength);
var collector = context.createScriptProcessor(0, 1);
var audioSource = context.createMediaElementSource(track);
var samplesCollected = 0;
@auser
auser / app.js
Last active January 26, 2021 01:59
angular.module('myApp',
['ngRoute', 'myApp.services', 'myApp.directives']
)
.config(function(AWSServiceProvider) {
AWSServiceProvider.setArn('arn:aws:iam::<ACCOUNT_ID>:role/google-web-role');
})
.config(function(StripeServiceProvider) {
StripeServiceProvider.setPublishableKey('pk_test_YOURKEY');
})
.config(function($routeProvider) {
@cjbell
cjbell / Gemfile
Created October 21, 2013 21:45
Sir Trevor Image Uploader (Rails + Carrierwave)
# Upload gems
gem "carrierwave"
gem "mini_magick", "~> 3.3"
gem "fog", "~> 1.3.1"
@njakobsen
njakobsen / live_database_dump.rb
Last active November 5, 2021 02:28
Live stream a database dump (or any other STDOUT) using Rails 4. Why would you want this? If you have a large database dump and want to avoid storing it in memory as Rails streams it. This allows pipe the dump directly into the http response instead of storing it as a file, sending it, and then deleting it. Let me know what you think! I've teste…
class DatabaseController < ApplicationController
def database_dump
database = Rails.configuration.database_configuration[Rails.env]["database"]
send_file_headers!(:type => 'application/octet-stream', :filename => "#{database}_#{Time.now.to_s(:human)}.backup")
pipe = IO.popen("pg_dump '#{database}' -F c")
stream = response.stream
while (line = pipe.gets)
stream.write line
sleep 0.0001 # HACK: Prevent server instance from sleeping forever if client disconnects during download
@hauleth
hauleth / Gemfile
Last active December 19, 2015 04:09 — forked from amscotti/mongo_urlshortener.rb
Simple Sinatra + Mongoid URL shortener (untested)
source 'https://rubygems.org'
gem 'sinatra'
gem 'slim'
gem 'mongoid'
gem 'bson_ext'
@yury
yury / application.css.scss
Last active December 17, 2015 19:39
Example of tiny, smalll and large column and shortcuts for bootstrap 3.0.x grid
// Grid shortcuts
// use with https://github.com/anjlab/bootstrap-rails
//
// Columns for phones
// - columns: .x[1-12]
// For small devices (tablets and small desktops)
// - columns: .s[1-12]
// - offsets: .so[0-11]
// - pushes: .sr[0-11]
// - pulls: .sl[0-11]
@turadg
turadg / application.rb
Last active August 1, 2024 08:35
Handle only 404s dynamically. It uses a normal controller and route for 404s, letting everything else go to the Rails default /public error pages. In my case it was to use the subdomain logic in my ApplicationController.
module MyApp
class Application < Rails::Application
require Rails.root + 'lib/custom_public_exceptions'
config.exceptions_app = CustomPublicExceptions.new Rails.public_path
end
end
@shaicoleman
shaicoleman / patcher.rb
Last active July 5, 2023 18:03
Initializer for mitigating CVE-2013-0156 and CVE-2013-0333 on all versions of rails
def rails_between(min, max)
Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new(min) && Gem::Version.new(Rails::VERSION::STRING) <= Gem::Version.new(max)
end
if rails_between('3.0.0', '3.0.18') || rails_between('3.1.0', '3.1.9') || rails_between('3.2.0', '3.2.10')
ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::XML)
end
if rails_between('2.0.0', '2.3.14')
ActionController::Base.param_parsers.delete(Mime::XML)
end