Skip to content

Instantly share code, notes, and snippets.

@vwall
vwall / [...].ts
Created March 7, 2024 02:34 — forked from nathanchase/[...].ts
Nuxt 3 Server API catch-all w/ caching, retries, and request/response logging (with total elapsed time)
// Here's my current implementation of a Nuxt 3 server API catch-all with caching, retries, and request/response logging with total elapsed time:
// Place in: /server/api/[...].ts
import LRU from 'lru-cache';
import { getCookie } from 'h3';
const config = useRuntimeConfig();
const cache = new LRU({
max: 100,
@vwall
vwall / db_fixtures_dump.rake
Created June 22, 2022 14:04 — forked from ecleel/db_fixtures_dump.rake
Rails 5: Dump Rails db to fixtures
# Original from http://snippets.dzone.com/posts/show/4468 by MichaelBoutros
#
# Optimized version which uses to_yaml for content creation and checks
# that models are ActiveRecord::Base models before trying to fetch
# them from database.
namespace :db do
namespace :fixtures do
desc 'Dumps all models into fixtures.'
task :dump => :environment do
models = Dir.glob(Rails.root + 'app/models/**.rb').map do |s|
2.hours.ago # => Fri, 02 Mar 2012 20:04:47 JST +09:00
1.day.from_now # => Fri, 03 Mar 2012 22:04:47 JST +09:00
Date.today.to_time_in_current_zone # => Fri, 02 Mar 2012 22:04:47 JST +09:00
Date.current # => Fri, 02 Mar
Time.zone.parse("2012-03-02 16:05:37") # => Fri, 02 Mar 2012 16:05:37 JST +09:00
Time.zone.now # => Fri, 02 Mar 2012 22:04:47 JST +09:00
Time.current # Same thing but shorter. (Thank you Lukas Sarnacki pointing this out.)
Time.zone.today # If you really can't have a Time or DateTime for some reason
Time.zone.now.utc.iso8601 # When supliyng an API (you can actually skip .zone here, but I find it better to always use it, than miss it when it's needed)
Time.strptime(time_string, '%Y-%m-%dT%H:%M:%S%z').in_time_zone(Time.zone) # If you can't use Time#parse
@vwall
vwall / Vue-cli-3-Phoenix-1.3-HOWTO.md
Created May 16, 2018 22:43 — forked from jpbecotte/Vue-cli-3-Phoenix-1.3-HOWTO.md
Vue-cli 3, Phoenix 1.3, a complete how-to

Introduction

I have been struggling to start a new project with Phoenix 1.3 and the new vue-cli 3 for Vue.js. There are tons of example already but none of them suited my needs, because:

  • I want to use the new Vue-cli to select the features that I want,
  • I do NOT want to setup Webpack (I know, what a shame!). The new Vue-cli includes the new vue-cli-service, which uses an instance of webpack-dev-server, so you don't have to import it manually in your project.
  • I do not want to use Brunch.

Create your Phoenix App

Assuming that you have Elixir and Phoenix 1.3 are both installed, let's build our new App.

@vwall
vwall / README.md
Created August 14, 2016 01:39 — forked from leemeichin/README.md
Apply Standard Competition Rankings to your leaderboard

Standard Competition Rankings

This class makes it easier to generate a leaderboard that complies with the Standard Competition Ranking system. That is, it takes joint/tied positions into account, and adjusts the positions accordingly.

Take the following list of users and points for example:

User    | Points
1         35
2         35
# Fixing permissions of packaged gems
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/10_fixing_permission.sh":
content: |
#!/usr/bin/env bash
# . /opt/elasticbeanstalk/containerfiles/envvars
. /opt/elasticbeanstalk/support/envvars
CACHE_GEM_DIR=$EB_CONFIG_APP_ONDECK/vendor/cache

OS X 10.10 Guide

Here's what I did to get things working.

1. Install Xcode 6

Yep, over at: https://developer.apple.com

2. Install the Command Line Tools (CLT)

WITH table_scans as (
SELECT relid,
tables.idx_scan + tables.seq_scan as all_scans,
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes,
pg_relation_size(relid) as table_size
FROM pg_stat_user_tables as tables
),
all_writes as (
SELECT sum(writes) as total_writes
FROM table_scans
@vwall
vwall / FbConsole.rb
Created February 12, 2014 19:55 — forked from rharjes/FbConsole.rb
#####################################################################
# Simplified Facebook interactions/navigation via Ruby/Mechanize. #
# Author: Robbie Harjes #
# Date: 6/8/2011 #
# Notes: Not liable for misuse; free for non-commercial projects.#
# This notice must remain intact if you use this code. #
#####################################################################
# Assuming that you have followed all the instructions from https://github.com/rumblelabs/asset_sync
# Put this in your deployment script
# Choose any environment here the important part is that your environment is using the same bucket for all environments
# than you only need to precompile assets once
RAILS_ENV=staging bundle exec rake assets:precompile
# You need to set git credentials otherwise it won't be able to commit
git config --global user.email "codeship@codeship.com"
git config --global user.name "Codeship Server"
# Add your manifest file so that rails can find digested version of files