Skip to content

Instantly share code, notes, and snippets.

View sidraval's full-sized avatar
🛠️
Wrenchin' away

Sid Raval sidraval

🛠️
Wrenchin' away
View GitHub Profile
@sidraval
sidraval / fake_attr_accessor
Last active December 22, 2015 18:49
Sometimes, an options hash is better than a bunch of instance variables. But referring to things like options[:key] is annoying, as is setting things via options[:key] = ... Enter method_missing.
# If your options hash is stored in @options
attr_accessor :options
def method_missing(meth,*args,&prc)
if options.keys.include?(meth.to_sym)
options[meth.to_sym]
elsif options.keys.include?(meth[0...-1].to_sym) && meth[-1] == "="
options[meth[0...-1].to_sym] = args.first
else
@sidraval
sidraval / s3_copy.rb
Last active August 29, 2015 13:57
Copy one S3 bucket's contents to another bucket; supports file > 5gb. Also copies over Access Control List options and encryption options. Won't overwrite files that already exist on the bucket you're copying to.
require 'aws-sdk'
class S3Copy
attr_reader :from_bucket, :to_bucket
def initialize(from_bucket, to_bucket)
access_key = ENV['AWS_ACCESS_KEY_ID']
secret_key = ENV['AWS_SECRET_ACCESS_KEY']
s3_instance = AWS::S3.new(access_key_id: access_key, secret_access_key: secret_key)
(ns gol-clojure.core-test
(:use clojure.contrib.mock)
(:require [clojure.test :refer :all]
[gol-clojure.core :refer :all]))
(deftest new-val-test
(testing "new-val"
(testing "when the center cell is dead"
(testing "with exactly 3 alive neighbors"
(let [matrix [[1 1 1] [0 0 0] [0 0 0]]]
intOrUppercase = (const () <$> posInt) <|> (const () <$> (satisfy isUpper))
@sidraval
sidraval / gist:b988364fcdf6cea4ef05
Created February 19, 2015 19:36
Type error fetching from database
data EventWithDistance = EventWithDistance
{ eventWithDistanceId :: Int
, eventWithDistanceEndedAt :: LocalTime
, eventWithDistanceName :: T.Text
, eventWithDistanceStartedAt :: LocalTime
, eventWithDistanceUserId :: Int
, eventWithDistanceAddress :: T.Text
, eventWithDistanceLat :: Float
, eventWithDistanceLon :: Float
, eventWithDistanceDistance :: Float
@sidraval
sidraval / gist:614cd09b5c6b3385d634
Last active August 29, 2015 14:20
ProductController
// ProductDelegate
import UIKit
protocol ProductDelegate: NSObjectProtocol {
func didReceiveProduct(product: Product)
func didReceiveProductImage(image: UIImage)
}
// ProductController
@sidraval
sidraval / FileWatcherFileListener.swift
Last active August 3, 2021 17:08
FileWatcher / FileListener
import Foundation
fileprivate let queue = DispatchQueue(label: "FileMonitorQueue", target: .main)
enum FileWatcherError: Error {
case directoryOpenFailed(Int32)
case directoryURLInvalid(URL)
}
final class FileWatcher {
@sidraval
sidraval / gist:9a36fa565683fd61675a003bac335f6b
Created November 4, 2019 02:52
Error without `@types/node` dev dependency
> tsc && npm run minify
node_modules/@types/node/index.d.ts:75:11 - error TS2300: Duplicate identifier 'IteratorResult'.
75 interface IteratorResult<T> { }
~~~~~~~~~~~~~~
node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6
41 type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
~~~~~~~~~~~~~~
@sidraval
sidraval / active_admin.rb
Created July 14, 2020 13:05
Active Admin configuration - modify each page with HTML injected into the body
module AdminPageLayoutOverride
def build_page(*args)
within super do
render "layouts/environment"
end
end
end
ActiveAdmin::Views::Pages::Base.send :prepend, AdminPageLayoutOverride
@sidraval
sidraval / .spacemacs
Created November 21, 2020 20:30
magit problems on spacemacs
;; -*- mode: emacs-lisp; lexical-binding: t -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Layer configuration:
This function should only modify configuration layer settings."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
;; `+distribution'. For now available distributions are `spacemacs-base'