Instantly share code, notes, and snippets.

Daniel Sager dsager

View GitHub Profile
View look_at_images.rb
# Script to get Google CLoud Vision annotations for a bunch of images
# Images in /images are expected to be also present in the specified GCS bucket
# setup:
# gem install google-cloud-vision
# export GOOGLE_CLOUD_KEYFILE="~/path/to/XX-XX.json"
require 'google/cloud/vision'
View wb_themes.rb
# script to load project data from the world bank and generate a training set
# for a classifier
# Get a list of projects from the world bank and filter out projects w/o abstracts & themes
# curl -s ',project_abstract,theme_namecode&source=IBRD&rows=50000'
# | jq '[.projects[] | select(.project_abstract? and .theme_namecode?)] | map({"text": [.project_name, .project_abstract.cdata] | join(" - "), "themes": .theme_namecode | map(.code)})'
# > wb-projects.json
#! /bin/bash
#create backup folder
mkdir -p "${BAKDIR}"
# find all `.idea` folders in home
if [ ! -e "${BAKFILE}" ]; then
#!/usr/bin/env bash
ROW="src/foo\ bar | foo | bar | baz |"
# cut out the directory first
TRIMMED_DIR="$(echo -e "${DIR}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
echo "> dir: $DIR"

The Devex NewsLab: Using Google Docs as a CMS

Note: This post was originally published on the Devex Tech Blog

This article describes our current content management solution and gives some insight on the parts of the implementation we think are interesting.

As you might know a big part of our website is dedicated to News content covering various aspects of international development. At Devex we usually publish around 10 articles per day which are sometimes planned and worked on several days or even weeks in advance. There are different people involved in the process including both internal and external writers, editors, researchers or marketing folks. Some of them contribute to the article's content while others just need to be aware what is going on to coordinate their own work like social media campaigns.


One in a has_many - Access Special Association Objects in ActiveRecord

ActiveRecord models that define a has_many association often need access to a specific entry of this list. Think of an user that has many email addresses but only one that is his primary address. Or a Blog post with many comments of which one is featured.

How a lot of people do it

A pattern that seems to be quite common is to [extend the association by implementing a method that gets you the specific record][ar-ass-extension]:

class User < ActiveRecord::Base
View get_gists.php
* Small script to fetch a list of a user's Gists on GitHub
* Copyright (c) 2014 Daniel Sager
* License: MIT,
$url = '';
View 2014
The MIT License (MIT)
Copyright (c) 2014 Daniel Sager
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
View mobile_detection.php
* Inspired by the neat Browser Gem for Ruby:
* Copyright (c) 2014 Daniel Sager
* License:
* @param null|string $ua

Keybase proof

I hereby claim:

  • I am dsager on github.
  • I am dsager ( on keybase.
  • I have a public key whose fingerprint is F92D 43DC 3A9E 32EC CF94 BB12 1CCF DB6B B557 139A

To claim this, I am signing this object: