Skip to content

Instantly share code, notes, and snippets.

Avatar
🐝
Alexa, ask the future of America to be great again! (try it)

Daniel (dB.) Doubrovkine dblock

🐝
Alexa, ask the future of America to be great again! (try it)
View GitHub Profile
@dblock
dblock / clickhacking.html
Created Sep 22, 2014
Clickjacking test.
View clickhacking.html
<html>
<head>
<title>Clickjacking Test</title>
</head>
<body>
<p>If you can see the website below, it's vulnerable to clickjacking.</p>
<iframe src="https://artsy.net/" width="500" height="500"></iframe>
</body>
</html>
View gist:fc2a864713d664f33f6a6bdeac3f518f
I am attesting that this GitHub handle dblock is linked to the Tezos account tz1ivFsNqtfLTSDh7uzqJ6pArNRG13pkJt4a for tzprofiles
sig:edsigtshxfYo5JbUmy38XPrRPwJY98j3nd79WEkVdrhBLVPxMAGSsyR4ai41QTnbygucGMENiRw7axCrFFKk6Cy41zcydx1o9JE
@dblock
dblock / carrierwave.rb
Created Jan 31, 2012
Delayed image processing with CarrierWave
View carrierwave.rb
CarrierWave.configure do |config|
...
end
Mongoid::Document::ClassMethods.send(:include, DelayedImageProcessing)
module CarrierWave
# http://sleeplesscoding.blogspot.com/2011/09/recreate-single-version-of.html
# Note: is_processing_delayed should be set before calling recreate_version! if the version depends on it.
@dblock
dblock / getWeek.js
Created Jul 13, 2011
get week of the year in JavaScript
View getWeek.js
function( d ) {
// Create a copy of this date object
var target = new Date(d.valueOf());
// ISO week date weeks start on monday
// so correct the day number
var dayNr = (d.getDay() + 6) % 7;
// Set the target to the thursday of this week so the
@dblock
dblock / api_logger.rb
Created Dec 10, 2012
API logger with Grape under Rails
View api_logger.rb
class ApiLogger < Grape::Middleware::Base
def before
Rails.logger.info "[api] Requested: #{request_log_data.to_json}\n" +
"[api] #{response_log_data[:description]} #{response_log_data[:source_file]}:#{response_log_data[:source_line]}"
end
private
def request_log_data
@dblock
dblock / dropbox.sh
Last active Sep 11, 2020
Auto-start Dropbox.
View dropbox.sh
#!/bin/bash
DROPBOX_USERS="root"
DAEMON=.dropbox-dist/dropboxd
start() {
echo "Starting dropbox..."
for dbuser in $DROPBOX_USERS; do
HOMEDIR=`getent passwd $dbuser | cut -d: -f6`
@dblock
dblock / git-delete-merged-branches.sh
Created Jun 9, 2011
Delete merged git branches.
View git-delete-merged-branches.sh
git branch --merged | grep -v master | xargs git branch -d
git branch -r --merged | awk -F'/' '/^ *origin/{if(!match($0, /(>|master)/)){print $2}}' | xargs git push origin --delete
@dblock
dblock / dokku-mongo-export.sh
Last active Jun 11, 2020
Backup MongoDB databases with Dropbox and Dokku
View dokku-mongo-export.sh
#!/bin/bash
set -e
echo "Backing up MongoDB databases to Dropbox ..."
dt=$(date +"%Y-%m-%d")
echo " today is $dt"
@dblock
dblock / api_page_helper.rb
Created Nov 2, 2011
pagination helper with Grape
View api_page_helper.rb
module ApiPageHelper
PAGINATE_OPTIONS = {
:default_page_size => 10
}
PAGINATE_PARAMS = [ "page", "offset", "size" ]
def paginate(coll, options = {})
options = PAGINATE_OPTIONS.merge(options)
if params[:page]
page = params[:page].to_i
size = (params[:size] || options[:default_page_size]).to_i
@dblock
dblock / grape-rackup-with-static.rb
Created Feb 20, 2012
Rackup static pages along with a Grape API, inspired by Rack::TryStatic
View grape-rackup-with-static.rb
class App
def initialize(options)
@try = ['', *options.delete(:try)]
@static = ::Rack::Static.new(
lambda { [404, {}, []] },
options)
end
def call(env)