Skip to content

Instantly share code, notes, and snippets.

View emdeeeks's full-sized avatar

Gareth Griffiths emdeeeks

View GitHub Profile
@kwent
kwent / cancelable.rb
Created December 30, 2018 23:17
Cancelable Rails concern
module Cancelable
extend ActiveSupport::Concern
included do
scope :with_cancelled, -> { where.not(cancelled_at: nil) }
scope :not_cancelled, -> { where(cancelled_at: nil) }
def cancel
# Use update_attributes and not touch to trigger after_save
@emdeeeks
emdeeeks / chat.rb
Created December 25, 2018 20:56 — forked from PurwadiPw/chat.rb
Simple chat ruby using eventmachine
#!/usr/bin/env ruby
require 'rubygems'
require 'eventmachine'
class Server
attr_accessor :connections
def initialize
@connections = []
@ximus
ximus / change tracking.rb
Last active October 20, 2023 13:54
5min illustration of cheap and dirty change tracking with activerecord
# WARN: this relies on the single threaded nature of our apps!
class ApplicationModel < ActiveRecord::Base
before_save do
if ChangeTracking.currently_change_tracking?
changeset << [:update, self, changes]
end
end
before_create do
#!/bin/bash
###########################################################################
#
# Created by
# Bohdan Kossak, CryptoLions.io
#
# Auto Installer for Jungle Network Generated by Monitor
###########################################################################
@TylerOderkirk
TylerOderkirk / fake_ap.py
Created May 4, 2018 03:41
dreamproxy hg r2
# from https://forum.micropython.org/viewtopic.php?p=19988&sid=7aaeff853648d6cd65371661708c1fba#p19988
import network
import time
import uos
from machine import Pin
led = Pin(2, Pin.OUT)
led.off() # actually turns it on
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
@0x263b
0x263b / discord_delete.rb
Created April 30, 2018 06:42
Delete discord post history
#!/usr/bin/env ruby
# encoding: utf-8
Encoding.default_external = "UTF-8"
Encoding.default_internal = "UTF-8"
require "open-uri"
require "json"
require "net/https"
require "uri"
@gduquesnay
gduquesnay / replace_nils_with_column_defaults.rb
Created April 5, 2018 16:15
Workaround for Persisting an empty string in an integer field with a default value converts to nil #32467
# see: https://github.com/rails/rails/issues/32467
# written with help from: https://github.com/noise-machines
# sponsored by: https://www.hiresuccess.com/
require "active_support/concern"
module ReplaceNilsWithColumnDefaults
extend ActiveSupport::Concern
included do
@carlweis
carlweis / soft_deletable.rb
Last active June 16, 2023 21:33
Allows soft deletes of an active record model
module SoftDeletable
extend ActiveSupport::Concern
included do
default_scope { where(deleted_at: nil) }
scope :deleted, -> { unscope(where: :deleted_at).where.not(deleted_at: nil) }
end
def delete
self.touch(:deleted_at) if has_attribute? :deleted_at
"use strict";
// This file was originally written by @drudru (https://github.com/drudru/ansi_up), MIT, 2011
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var ANSI_COLORS = [[{ color: "0, 0, 0", "class": "ansi-black" }, { color: "187, 0, 0", "class": "ansi-red" }, { color: "0, 187, 0", "class": "ansi-green" }, { color: "187, 187, 0", "class": "an
@blaze182
blaze182 / auth_helpers.rb
Created September 30, 2017 17:39
Request specs devise_token_auth Authentication helpers
# spec/support/requests/auth_helpers.rb
module Requests
module AuthHelpers
module Extensions
def sign_in(user)
let(:auth_helpers_auth_token) {
self.public_send(user).create_new_auth_token
}
end