Skip to content

Instantly share code, notes, and snippets.

View lzell's full-sized avatar

Lou Zell lzell

View GitHub Profile
@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 / 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];
How?
~$ which rvm
~$ alias | grep 'rvm='
~$ rvm --version
rvm 0.1.32 by Wayne E. Seguin ([email protected]) [http://rvm.beginrescueend.com/]
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
@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]