Skip to content

Instantly share code, notes, and snippets.

@jstanley0
jstanley0 / pg_ps.rb
Created August 28, 2018 16:24
list and kill Postgres queries from a Rails console
# list pid, execution time, and query text for running queries
def pg_ps
now = Time.now
ActiveRecord::Base.connection.execute("SELECT pid, query, query_start FROM pg_stat_activity WHERE state='active'").to_a.each do |q|
printf "%8d %10.2f %s\n", q['pid'], now - DateTime.parse(q['query_start']), q['query']
end
nil
end
# cancel the current query for the given process
@arjunsharma97
arjunsharma97 / m4atowav.py
Created April 1, 2018 06:36
Python script to convert m4a files to wav files
# Packages reqd: pydub, ffmpeg
# pydub - pip install pydub
# ffmpeg:
# sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next
# sudo apt-get update
# sudo apt-get install ffmpeg
## Load the m4a files (in M4a_files.tar.gz)
@christhekeele
christhekeele / default_behaviour.ex
Last active April 22, 2024 02:05
Behaviours with Defaults for Elixir
defmodule Default.Behaviour do
@moduledoc """
Creates a behaviour that carries its own default implementation.
When used into a behaviour module, when that module in turn is used, all functions
defined on it are given to the using module.
This allows you to have concrete implementations of the behaviour's default functionality
for testing, unlike cramming them all into a __using__ macro.
@mxhold
mxhold / download_slack_emoji.md
Last active April 1, 2020 03:02
Download Slack Emoji

✨ Download Slack Emoji ✨

Quick way to export your Slack team's emoji (concurrently!)

Prerequisites

  1. Create an API token for your Slack team
@eliotsykes
eliotsykes / README.md
Last active August 30, 2022 05:46
Techniques for Removing ActiveRecord Callbacks

I certainly have plenty of ar callbacks, wondering what patterns you use to avoid controller bloat or factories for every model?

Sometimes option 1) Extract the callback to its own method and call it:

# File app/models/user.rb
class User < ApplicationRecord

-  after_commit { |user| Mailer.registration_confirmation(user).deliver_later }, on: :create
+  def send_registration_confirmation
@bdangit
bdangit / dvm.fish
Last active November 28, 2016 23:47 — forked from 7sDream/dvm.fish
Set up dvm command for fish shell.
# Docker Version Manager wrapper for *nix
# Implemented as a POSIX-compliant function
# Should work on sh, dash, bash, ksh, zsh
# To use, source this file from your bash profile
begin # This ensures the entire script is downloaded
set DVM_SCRIPT_SOURCE $_
# __dvm_has() {
# type "$1" > /dev/null 2>&1
@lmarkus
lmarkus / README.MD
Last active May 21, 2024 02:50
Extracting / Exporting custom emoji from Slack

Extracting Emoji From Slack!

Slack doesn't provide an easy way to extract custom emoji from a team. (Especially teams with thousands of custom emoji) This Gist walks you through a relatively simple approach to get your emoji out.

If you're an admin of your own team, you can get the list of emoji directly using this API: https://api.slack.com/methods/emoji.list. Once you have it, skip to Step 3

HOWEVER! This gist is intended for people who don't have admin access, nor access tokens for using that list.

Follow along...

@wesbos
wesbos / gulpfile.js
Last active October 21, 2019 19:38
FAST Browserify + Reactify + Babelify
// Update: Hey Folks - I've got a full Gulpfile with everything else over at https://github.com/wesbos/React-For-Beginners-Starter-Files
var source = require('vinyl-source-stream');
var gulp = require('gulp');
var gutil = require('gulp-util');
var browserify = require('browserify');
var reactify = require('reactify');
var babelify = require('babelify');
var watchify = require('watchify');
var notify = require('gulp-notify');
@kevin-smets
kevin-smets / iterm2-solarized.md
Last active May 23, 2024 23:26
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k

@leon
leon / SlickUserService.scala
Created March 12, 2013 07:55
Secure Social UserService Slick implementation (Not Working)
package service
import play.api._
import securesocial.core._
import securesocial.core.providers.Token
import securesocial.core.UserId
import models._
class SlickUserService(application: Application) extends UserServicePlugin(application) {