Skip to content

Instantly share code, notes, and snippets.

@rbq
rbq / tensorflow_test_script
Last active Oct 15, 2019 — forked from donigian/tensorflow_test_script
TensorFlow Test Script
View tensorflow_test_script
import tensorflow as tf
with tf.device('/cpu:0'):
a_c = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a-cpu')
b_c = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b-cpu')
c_c = tf.matmul(a_c, b_c, name='c-cpu')
with tf.device('/gpu:0'):
a_g = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a-gpu')
b_g = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b-gpu')
@rbq
rbq / convert_sqlite_booleans.rb
Created Apr 30, 2019
Rails 6 migrations to upgrade SQLite booleans from t/f to 1/0
View convert_sqlite_booleans.rb
class ConvertSqliteBooleans < ActiveRecord::Migration[6.0]
BOOLEANS = [
[ 'table_name', 'column_name' ],
[ 'table_name', 'column_name' ],
]
def up
BOOLEANS.each do |table, column|
execute "UPDATE #{table} SET #{column} = 1 WHERE #{column} = 't';"
execute "UPDATE #{table} SET #{column} = 0 WHERE #{column} = 'f' OR #{column} IS NULL;"
@rbq
rbq / docker.yaml
Last active Nov 14, 2021
Install Docker CE on Ubuntu using Ansible
View docker.yaml
---
- hosts: all
tasks:
- name: Install prerequisites for Docker repository
apt:
name: ['apt-transport-https', 'ca-certificates', 'curl', 'gnupg2', 'software-properties-common']
update_cache: yes
- name: Add Docker GPG key
apt_key:
@rbq
rbq / create_labels.sh
Created Mar 9, 2017 — forked from omegahm/create_labels.sh
Create Gtihub labels from Bash
View create_labels.sh
#!/usr/bin/env bash
# Colours picked from https://robinpowered.com/blog/best-practice-system-for-organizing-and-tagging-github-issues/
###
# Label definitions
###
declare -A LABELS
# Platform
@rbq
rbq / Gemfile
Last active Apr 27, 2020
Convert notes from Snippets.me to Quiver
View Gemfile
source 'https://rubygems.org'
gem 'data_mapper'
gem 'dm-sqlite-adapter'
View rdoc-patch.rb
class RDoc::Markup::Formatter
def parse_url url
case url
when /^rdoc-label:([^:]*)(?::(.*))?/ then
scheme = 'link'
path = "##{$1}"
id = " id=\"#{$2}\"" if $2
when /([A-Za-z]+):(.*)/ then
scheme = $1.downcase
path = $2
View Animal.txt
#!/usr/bin/env ruby
# coding: utf-8
require 'sinatra'
get '/:animal' do
@all_animals = ['Cat', 'Dog']
@animal = params[:animal] if @all_animals.include? params[:animal]
erb :index
end
@rbq
rbq / config.ru
Created Apr 22, 2013
Problem: not_found doesn't work at all
View config.ru
# coding: utf-8
require 'rack/urlmap'
require File.join(File.dirname(__FILE__), 'app')
require File.join(File.dirname(__FILE__), 'api', 'v1')
routes = Rack::URLMap.new(
'/' => Sinatra::Application,
'/api/v1/' => ApiV1
)
@rbq
rbq / uberspace-gem-nokogiri
Created Sep 22, 2011
Install the Nokogiri rubygem on Uberspace
View uberspace-gem-nokogiri
# Instructions: http://nokogiri.org/tutorials/installing_nokogiri.html
# See also: https://github.com/tenderlove/nokogiri/issues/243
toast arm libxml libxslt && \
gem install nokogiri -- \
--with-xml2-lib=$HOME/.toast/armed/lib \
--with-xml2-include=$HOME/.toast/armed/include/libxml2 \
--with-xslt-dir=$HOME/.toast/armed
bundle config build.nokogiri \
@rbq
rbq / app.rb
Created Sep 6, 2011
Sinatra route for SASS files
View app.rb
get '/:name.css' do
content_type 'text/css', :charset => 'utf-8'
response.headers['Cache-Control'] = 'public, max-age=3600'
sass :"stylesheets/#{params[:name]}"
end