Skip to content

Instantly share code, notes, and snippets.

Avatar
🛠️
Wrenchin' away

Sid Raval sidraval

🛠️
Wrenchin' away
View GitHub Profile
@sidraval
sidraval / .spacemacs
Created Nov 21, 2020
magit problems on spacemacs
View .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'
@sidraval
sidraval / active_admin.rb
Created Jul 14, 2020
Active Admin configuration - modify each page with HTML injected into the body
View active_admin.rb
module AdminPageLayoutOverride
def build_page(*args)
within super do
render "layouts/environment"
end
end
end
ActiveAdmin::Views::Pages::Base.send :prepend, AdminPageLayoutOverride
@sidraval
sidraval / gist:9a36fa565683fd61675a003bac335f6b
Created Nov 4, 2019
Error without `@types/node` dev dependency
View gist:9a36fa565683fd61675a003bac335f6b
> 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 / FileWatcherFileListener.swift
Last active Aug 3, 2021
FileWatcher / FileListener
View FileWatcherFileListener.swift
import Foundation
fileprivate let queue = DispatchQueue(label: "FileMonitorQueue", target: .main)
enum FileWatcherError: Error {
case directoryOpenFailed(Int32)
case directoryURLInvalid(URL)
}
final class FileWatcher {
View gist:614cd09b5c6b3385d634
// ProductDelegate
import UIKit
protocol ProductDelegate: NSObjectProtocol {
func didReceiveProduct(product: Product)
func didReceiveProductImage(image: UIImage)
}
// ProductController
@sidraval
sidraval / gist:b988364fcdf6cea4ef05
Created Feb 19, 2015
Type error fetching from database
View gist:b988364fcdf6cea4ef05
data EventWithDistance = EventWithDistance
{ eventWithDistanceId :: Int
, eventWithDistanceEndedAt :: LocalTime
, eventWithDistanceName :: T.Text
, eventWithDistanceStartedAt :: LocalTime
, eventWithDistanceUserId :: Int
, eventWithDistanceAddress :: T.Text
, eventWithDistanceLat :: Float
, eventWithDistanceLon :: Float
, eventWithDistanceDistance :: Float
View gist:8da92635eaf5086a480b
intOrUppercase = (const () <$> posInt) <|> (const () <$> (satisfy isUpper))
View clojure mocks trouble
(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]]]
@sidraval
sidraval / s3_copy.rb
Last active Aug 29, 2015
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.
View s3_copy.rb
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)
@sidraval
sidraval / fake_attr_accessor
Last active Dec 22, 2015
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.
View fake_attr_accessor
# 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