Skip to content

Instantly share code, notes, and snippets.

View akramhussein's full-sized avatar

Akram Hussein akramhussein

  • Vektor
View GitHub Profile
@akramhussein
akramhussein / README.md
Last active October 13, 2023 20:24
Installing SPM12 on Apple Silicon (macOS)

Instructions

These instructions are for installing and running SPM12 (standalone) on macOS with Apple Silicon.

Installation

SPM12

  1. Download SPM12 (standalone) here
@akramhussein
akramhussein / GoogleSpeechToTextStreamingTap.swift
Created December 1, 2017 19:03
AudioKit Tap to convert microphone data for Google Speech-to-Text API
open class GoogleSpeechToTextStreamingTap {
internal var converter: AVAudioConverter!
@objc public init(_ input: AKNode?, sampleRate: Double = 16000.0) {
let format = AVAudioFormat(commonFormat: AVAudioCommonFormat.pcmFormatInt16, sampleRate: sampleRate, channels: 1, interleaved: false)!
self.converter = AVAudioConverter(from: AudioKit.format, to: format)
self.converter?.sampleRateConverterAlgorithm = AVSampleRateConverterAlgorithm_Normal
@akramhussein
akramhussein / always_listen.py
Created October 25, 2017 10:19
Snips.ai - always listen MQTT app
import json
import paho.mqtt.client as mqtt
# MQTT client to connect to the bus
mqtt_client = mqtt.Client()
def on_connect(client, userdata, flags, rc):
print('Connected')
mqtt_client.subscribe('#') # subscribe to all messages
mqtt_client.publish('hermes/asr/toggleOn') # Start recording audio
@akramhussein
akramhussein / gist:88192f612b4e485bb34c63da992959b7
Created September 25, 2016 09:29
Get list of images from Digital Ocean
export DIGITAL_OCEAN_TOKEN=''
curl -X GET --silent "https://api.digitalocean.com/v2/images?per_page=999" -H "Authorization: Bearer $DIGITAL_OCEAN_TOKEN"
@akramhussein
akramhussein / Product.swift
Created August 26, 2016 07:48
Realm+ObjectMapper Example
import Foundation
import RealmSwift
import ObjectMapper
class Product: Object, Mappable
{
dynamic var name = ""
dynamic var price = 0.0
var discount = RealmOptional<Float>() {
@akramhussein
akramhussein / Array+RemoveObjectByClass.swift
Created March 27, 2016 09:23
Array+RemoveObjectByClass.swift
extension Array
{
mutating func removeObjectByClass<T>(t: T.Type)
{
for (index, object) in self.enumerate()
{
if let _ = object as? T
{
self.removeAtIndex(index)
}
@akramhussein
akramhussein / CrashlyticsLogger.swift
Created August 11, 2015 15:07
CocoaLumberjack Custom Crashlytics Logger in Swift
import Foundation
import CocoaLumberjack
import Crashlytics
class CrashlyticsLogger : DDAbstractLogger
{
static let sharedInstance = CrashlyticsLogger()
private var _logFormatter : DDLogFormatter?
override var logFormatter: DDLogFormatter? {
@akramhussein
akramhussein / CustomLogFormatter.swift
Created August 11, 2015 15:03
CustomLogFormatter for CocoaLumberjack - Swift
import Foundation
import CocoaLumberjack
class CustomLogFormatter : NSObject, DDLogFormatter
{
private var dateFormatter : NSDateFormatter!
override init()
{
self.dateFormatter = NSDateFormatter()
@akramhussein
akramhussein / AccessSwitchCommands.swift
Last active August 29, 2015 14:25
Handle Access Switch devices in iOS - Swift
var commands = [UIKeyCommand]()
var onceToken : dispatch_once_t = 0
override var keyCommands : [AnyObject]? {
get {
dispatch_once(&onceToken) {
self.commands = [
UIKeyCommand(input: " ", modifierFlags: nil, action: "spacePressed:"),
UIKeyCommand(input: "\r", modifierFlags: nil, action: "enterPressed:"),
UIKeyCommand(input: "0", modifierFlags: nil, action: "zeroPressed:"),
@akramhussein
akramhussein / String+RemoveWords.swift
Last active August 29, 2015 14:18
String+RemoveWords Extension
extension String
{
func removeWords(words: [String]) -> String
{
var cleanedString = self
// Remove common words
for word in words
{
cleanedString = cleanedString.stringByReplacingOccurrencesOfString(word, withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)