Skip to content

Instantly share code, notes, and snippets.

View drewdeponte's full-sized avatar

Drew De Ponte drewdeponte

View GitHub Profile
@drewdeponte
drewdeponte / TextWithAttributedString.swift
Created February 19, 2021 03:56
SwiftUI TextWithAttributedString
public struct TextWithAttributedString: NSViewRepresentable {
public typealias NSViewType = NSTextField
public class Coordinator: NSObject, NSGestureRecognizerDelegate {
let doubleTapCallback: () -> ()
public init(doubleTapCallback: @escaping () -> ()) {
self.doubleTapCallback = doubleTapCallback
}

Keybase proof

I hereby claim:

  • I am drewdeponte on github.
  • I am cyphactor (https://keybase.io/cyphactor) on keybase.
  • I have a public key ASAoIB5Zt8ea9NUiFxVewjRNdMKv3uytqIDZy12KPoBSGAo

To claim this, I am signing this object:

@drewdeponte
drewdeponte / membership_controller_good_vs_bad.rb
Created July 13, 2018 20:29
Don't use params objects inside methods other than your controller action methods in web frameworks
################### BAD ########################
class MembershipsControllerBad < ApplicationController
def create # the actual controller action
...
...
create_invite(@org, current_user, email, existing_user)
...
...
fn get_possible_files_from_glob<T: Iterator<Item=Option<String>>>() -> Result<T, glob::PatternError> {
glob("**/*").map(|paths| paths.flat_map(identity).filter(|path| path.is_file()).map(|path_buf| path_buf.to_str()))
}

Keybase proof

I hereby claim:

  • I am cyphactor on github.
  • I am cyphactor (https://keybase.io/cyphactor) on keybase.
  • I have a public key ASAoIB5Zt8ea9NUiFxVewjRNdMKv3uytqIDZy12KPoBSGAo

To claim this, I am signing this object:

struct PossibleAlternatePath {
path: std::path::Path
}
impl From<std::path::Path> for PossibleAlternatePath {
fn from(path: std::path::Path) -> Self {
PossibleAlternatePath { path: path }
}
}
@drewdeponte
drewdeponte / gist:b404861a25a2bd9b7e082b90329daf80
Created April 8, 2016 21:19
print netstat from proc watch -n 1 "cat /proc/net/netstat | ./drew_netstat.rb"
#!/usr/bin/env ruby
stats_hash = {}
stats_lines = $stdin.readlines
headers = stats_lines[0].gsub(/TcpExt: /, '').split(' ')
stats = stats_lines[1].gsub(/TcpExt: /, '').split(' ')
@drewdeponte
drewdeponte / lotus_view_with_serialization_and_without_html_escaping.rb
Created December 10, 2015 06:53
Lotus View with Serialization and without html escaping
module ShipmunkApi::Views::Users
class Create
include Lotus::View
format :v1
def render
_raw(JSON.generate({foo:'hello'}))
end
end
end
@drewdeponte
drewdeponte / lotus_view_with_serialization_and_automatic_html_escape.rb
Last active December 10, 2015 06:47
Lotus View with Custom Render for Serialization and automatic html escape
module ShipmunkApi::Views::Users
class Create
include Lotus::View
format :v1
def render
JSON.generate({foo:'hello'})
end
end
end
@drewdeponte
drewdeponte / selecta_command.vim
Created August 8, 2015 20:50
An attempt at implementing support for selecta in neovim
function! SelectaCommand(choice_command, selecta_args, vim_command)
let dict = { 'vim_command': a:vim_command, 'temps': { 'result': tempname() }, 'name': 'SelectaCommand' }
function! dict.on_exit(id, code)
bd! " close terminal buffer
if a:code == 0 " success
if filereadable(self.temps.result)
let l:selection = readfile(self.temps.result)[0]
echom "selecta: selected: ".selection