Skip to content

Instantly share code, notes, and snippets.

View cbess's full-sized avatar
💭
Coding for Jesus' glory. Soli Deo gloria

C. Bess cbess

💭
Coding for Jesus' glory. Soli Deo gloria
View GitHub Profile
@cbess
cbess / TimeParts.swift
Last active May 5, 2023 07:59
Swift: Seconds to minutes and hours parts
/// Represents parts of time
struct TimeParts: CustomStringConvertible {
var seconds = 0
var minutes = 0
/// The string representation of the time parts (ex: 07:37)
var description: String {
return NSString(format: "%02d:%02d", minutes, seconds) as String
}
}
@cbess
cbess / empty.theme.html
Last active April 13, 2023 01:29
Empty Blogger Theme HTML
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data'
xmlns:expr='http://www.google.com/2005/gml/expr'>
<head>
<meta charset='utf-8' />
<meta content='IE=edge' http-equiv='X-UA-Compatible' />
<meta content='width=device-width, initial-scale=1' name='viewport' />
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
@cbess
cbess / DispatchQueueDelay.swift
Last active December 6, 2022 09:39
Swift DispatchQueue throttle and debounce class (thread-safe)
//
// DispatchQueueDelay.swift
//
// Created by C. Bess on 9/17/19.
// MIT - Soli Deo gloria - perfectGod.com
//
// refs:
// - https://gist.github.com/fjcaetano/ff3e994c4edb4991ab8280f34994beb4
// - https://www.craftappco.com/blog/2018/5/30/simple-throttling-in-swift
@cbess
cbess / gist:1431627
Created December 4, 2011 23:21
Update Django model from dictionary
def update_model(model, save_update=True, **kwargs):
"""Updates the specified model instance using the keyword arguments as the model
property attributes and values.
Example usage:
update_model(mymodel, save_update=True, **some_dictionary)
"""
for attr, val in kwargs.items():
setattr(model, attr, val)
@cbess
cbess / mysql-sp.md
Last active September 23, 2022 18:47
mysql stored procedure call from golang

A stored procedure that saves (insert/update) a URL, then returns the id for the record.

Works in Go v1.11.6+ and MySQL 5.7+.

DELIMITER ;;

CREATE DEFINER=`root`@`%` PROCEDURE SaveUrl(
    IN p_url varchar(8200),
    IN p_title text
@cbess
cbess / Log.swift
Last active September 2, 2021 07:25
Simple Logger class in Swift 4.x
import Foundation
/// Represents the Log facilities
struct Log {
/// Prints in debug only
static func debug(_ msg: String, line: Int = #line, fileName: String = #file, funcName: String = #function) {
#if DEBUG
let fname = (fileName as NSString).lastPathComponent
print("[\(fname) \(funcName):\(line)]", msg)
#endif
@cbess
cbess / s3_uploader.go
Created June 16, 2021 01:36
golang S3 upload module with gzip file compression
package uploader
import (
"bytes"
"compress/gzip"
"myapp/internal/config"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
@cbess
cbess / provision.py
Created June 14, 2021 17:45
python-digitalocean server provisioning Py3 module
# the server provisioning module
# uses: python-digitalocean==1.16.0
# ref: https://developers.digitalocean.com/documentation/v2/#droplets
import digitalocean
import os
class ProvisionServerException(Exception):
pass
@cbess
cbess / gist:1393058
Created November 25, 2011 08:36
Set NSView layer background image
// Sets the view's background to the given image
// prior to call, you may need to execute: `view.wantsLayer = YES`
void SetBackgroundImage(NSView *view, NSString *imageName)
{
view.layer.contents = (id)[NSImage imageNamed:imageName];
}
@cbess
cbess / gist:4444374
Last active March 16, 2020 06:10
Xcode Delete and Duplicate Selected Lines
<key>Customized</key>
<dict>
<key>Delete Line</key>
<string>selectLine:, deleteBackward:</string>
<key>Duplicate Lines</key>
<string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string>
<key>Duplicate Current Line</key>
<string>moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:</string>
</dict>