Skip to content

Instantly share code, notes, and snippets.

View lzell's full-sized avatar

Lou Zell lzell

View GitHub Profile
@lzell
lzell / gist:143380
Created July 9, 2009 02:35
Send mail from your gmail account
require 'net/smtp'
require 'rubygems'
require 'tlsmail'
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
class GMailer
SMTP_ADDR = 'smtp.gmail.com'
def initialize(opts = {})
unless opts[:login] && opts[:password]
module Truncate
# only add ellipsis on a word boundary, do not break a word
def truncate(char_num)
# return a new string
self.gsub(/((?:.|\n){#{char_num}}[\w.]*)((?:.|\n)*)/) {$2.empty? ? $1 : $1 + '...'}
end
end
class String
include Truncate
How?
~$ which rvm
~$ alias | grep 'rvm='
~$ rvm --version
rvm 0.1.32 by Wayne E. Seguin ([email protected]) [http://rvm.beginrescueend.com/]
@lzell
lzell / JPUtils.m
Created October 9, 2012 03:39
JPUtils implementation
#import "JPUtils.h"
extern void
JPUpdateDelegates(id<JPManagerDelegate,JPDeviceDelegate> aDelegate)
{
JPManager *manager = [JPManager sharedManager];
[manager setDelegate:aDelegate];
for(JPDevice *dev in [manager connectedDevices])
{
[dev setDelegate:aDelegate];
@lzell
lzell / string_to_data_back.swift
Last active September 23, 2019 19:28
Swift string to data (bytes) and back
// (string, swift, bytes, data, buffer, cstring)
print("--- using nulTerminated ---")
let x : String = "hello"
let buf = x.nulTerminatedUTF8
print(buf)
print("\n--- using [UInt8] ---")
let buf2 : [UInt8] = [UInt8](x.utf8)
print(buf2)
@lzell
lzell / dns_resolve_multicast.swift
Created June 21, 2016 21:52
DNS resolve multicast os x
var res : __res_9_state = __res_9_state()
res_9_ninit(&res)
var addr: in_addr = in_addr()
inet_aton("224.0.0.251", &addr)
res.nsaddr_list.0.sin_addr = addr
res.nsaddr_list.0.sin_family = sa_family_t(AF_INET)
res.nsaddr_list.0.sin_port = in_port_t(5353).bigEndian
res.nscount = 1
@lzell
lzell / xctesting_in_repl_or_script.swift
Created August 11, 2016 20:01
Using XCTest in the swift repl or standalone script
// Start repl with:
// $ xcrun swift -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks
// Or run as script:
// $ xcrun swift -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks %
import Foundation
if dlopen("/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/XCTest.framework/Versions/A/XCTest", RTLD_NOW) == nil {
@lzell
lzell / figma_plugin_setup_esbuild.md
Last active May 18, 2023 17:11
Figma plugin setup for bundling multiple source files

2023-05-17

(figma plugin, getting started)

  • Open the Figma desktop app

  • Go to Plugins > Development > New Plugin > Figma Design > Run Once
    This creates a plugin with starter source code to drop five orange rectangles on the canvas

  • Setup the plugin:

    cd <project-dir>
    
@lzell
lzell / figma_1.67_to_1.68.diff
Created June 24, 2023 15:27
Figma plugin API diff between versions 1.67 and 1.68
diff --git a/plugin-typings/plugin-api.d.ts b/plugin-typings/plugin-api.d.ts
index d299a90..c4ea706 100644
--- a/plugin-typings/plugin-api.d.ts
+++ b/plugin-typings/plugin-api.d.ts
@@ -12,7 +12,8 @@ declare type ArgFreeEventType =
interface PluginAPI {
readonly apiVersion: '1.0.0'
readonly command: string
- readonly editorType: 'figma' | 'figjam'
+ readonly editorType: 'figma' | 'figjam' | 'dev'
@lzell
lzell / DoesThisSwiftUILeak.md
Created January 7, 2024 19:29
Inspecting if dependency on Observable leaks in SwiftUI

Contents of MyApp.swift

import SwiftUI

@main
struct AnimateOnObservedPropertyChangeApp: App {
    @State var trigger = false

    var body: some Scene {