Skip to content

Instantly share code, notes, and snippets.

User.where(weight_unit: "lbs").where.not(weight: nil).find_each { |u| u.athlete_profile.update!(precise_weight: (u.weight * 0.45359237).round(1)) }
@qoobaa
qoobaa / init.lua
Created January 2, 2017 16:43
SDS011 + ESP8266
DEVICE_ID="pmsensor-" .. string.format("%02X", node.chipid())
BOOT_WAIT = 3
DWEET_INTERVAL = 60
LED_PIN = 4
pm25 = nil
pm10 = nil
function led(state)
require "open-uri"
require "fileutils"
open("attachments.csv").each do |line|
path, url = line.split(",", 2)
puts path
FileUtils.mkdir_p(File.dirname(path))
open(path, "w") { |f| f.write(open(url).read) } unless File.exist?(path)
end
Attachment.find_each { |a| f = a.file; f.fog_authenticated_url_expiration = 24.hours.to_i; puts "#{f.path},#{f.url}" }
@qoobaa
qoobaa / userdata.sh
Last active December 15, 2016 12:57
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
# reduce the server load and free as much memory as we can
service unicorn stop
service nginx stop
service postgresql stop
# remove the old postgresql
@qoobaa
qoobaa / Deutsch.txt
Last active November 27, 2016 17:35
aleja|die Allee, -n|
starówka|die Altstadt, die Altstädte<br>|
zagranica|das Ausland|
wieś|das Dorf, die Dörfer|
okolica (G…)|die Gegend, -en|
duże miasto|die Großstadt, die Großstädte|
stolica|die Hauptstadt, die Hauptstädte|
numer domu|die Hausnummer, -n|
centrum miasta|die Innenstadt, die Innenstädte|
małe miasto|die Kleinstadt, die Kleinstädte|
User.where("NOT EXISTS (SELECT 1 FROM athlete_profiles WHERE athlete_profiles.fl_uid = users.fl_uid)").find_each { |user| Athlete::ProfileBuilder.new(user_id: user.id).call }
require "optparse"
require "json"
require "net/http"
options = {}
OptionParser.new do |parser|
parser.banner = "Usage: sds011.rb [options]"
parser.on("-dDEVICE", "--device DEVICE", "SDS011 serial port path") do |device|
require "json"
require "net/http"
SDS011_DEV = "/dev/ttyUSB0"
FIREBASE_HOST = "airsensor.firebaseio.com"
AUTH_TOKEN = "B1K9LMmwtYR8EwXtSTztUUwhaC7IjE5HWUOOuSfk"
header, command, pm25l, pm25h, pm10l, pm10h, id1, id2, sum, tail = IO.read(SDS011_DEV, 10).unpack("CCCCCCCCCC")
if header == 0xAA && command == 0xC0 && (pm25l + pm25h + pm10l + pm10h + id1 + id2) % 256 == sum && tail == 0xAB
(add-hook 'js2-mode-hook 'qoobaa/js2-mode-setup)
(defun qoobaa/js2-mode-setup ()
(let ((local-eslint (expand-file-name "node_modules/.bin/eslint" (projectile-project-root))))
(when (file-exists-p local-eslint)
(setq flycheck-javascript-eslint-executable local-eslint)
(js2-mode-hide-warnings-and-errors)
(flycheck-mode t)
(flycheck-select-checker 'javascript-eslint))))