Skip to content

Instantly share code, notes, and snippets.

View tmm1's full-sized avatar

Aman Gupta Karmani tmm1

View GitHub Profile
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active April 26, 2024 10:15
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

#include <android/log.h>
#include <jni.h>
#include <binder/Binder.h>
#include <binder/Parcel.h>
#include <binder/IServiceManager.h>
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@sgdan
sgdan / gzip.kts
Last active April 4, 2024 06:02
Kotlin code to compress/uncompress a string with gzip
import java.io.ByteArrayOutputStream
import java.io.File
import java.nio.charset.StandardCharsets.UTF_8
import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream
fun gzip(content: String): ByteArray {
val bos = ByteArrayOutputStream()
GZIPOutputStream(bos).bufferedWriter(UTF_8).use { it.write(content) }
return bos.toByteArray()
@joestump
joestump / San_Francisco.mkd
Created February 1, 2014 02:05
Here are two tours of San Francisco and the surrounding area. Both take about a day. One is entirely within the city and can be done entirely via public transportation. The other requires a car and gets you outside of SF to some of the wonderful sites that comprise the Yay Area.

San Francisco by Foot

  • You can start anywhere in the Castro, Mission (home of the burrito), or downtown. I'd recommend starting at Chow at Market & Church or The Pork Store on 16th at Valencia. If you wanted to go upscale on the weekend, Maverick at 17th and Mission is a fantastic brunch. Another option is to start in Chinatown (just north of Union Squre) for dim sum.
  • From Castro take one of the N, J, etc. trains (every light rail train route in the city intersects at Church and Market) down to the Powell Street station. From the Mission you can take BART a couple of stops up to Powell Street.
  • Once at Powell Street hop on the Powell Street trolley. A quintessential SF experience.
  • Take the trolley up through the city where it will eventually stop at Lombard Street, which is known as the most crooked street in the world. Walk down the hill, take a few pictures and laugh at the tourists trying to drive down the damn thing.
  • Once at the bottom of the hill, turn left. You'll be walking towards the w
@svagionitis
svagionitis / Create_Iframe_Index_M3U8.bash
Last active January 13, 2024 13:42
Segment an mp4 file to HLS streaming files
#!/bin/bash
# Create an Iframe index from HLS segmented streams
# $1: Filename to be created
# $2: Location of segmented ts files
# Check how many arguments
if [ $# != 2 ]; then
echo "Usage: $0 [Input filename] [Location of segmented streams]"
exit 1;
fi
@chriso
chriso / http.go
Last active September 9, 2023 17:16
// Go HTTP Hello World Server + non-blocking I/O test.
//
// This requires gotip (https://pkg.go.dev/golang.org/dl/gotip) for:
// - https://github.com/golang/go/commit/41893389
// - https://github.com/golang/go/commit/c5c21845
// - https://github.com/golang/go/commit/a17de43e
//
// Compile http.wasm:
//
// $ GOOS=wasip1 GOARCH=wasm gotip build -o http.wasm http.go
@wsargent
wsargent / docker_cheat.md
Last active August 31, 2023 12:10
Docker cheat sheet
@KatelynHaworth
KatelynHaworth / notifyAddrChange.go
Created June 22, 2017 05:03
A simple go program leveraging the Window API to listen for IPv4 network address change events
package main
import (
"log"
"syscall"
"unsafe"
"golang.org/x/sys/windows"
)
@lrytz
lrytz / z-automator.png
Last active February 4, 2023 21:20
Shortcut for Syntax Highlighting in Keynote
@tmm1
tmm1 / em-rpc-server.rb
Created April 16, 2009 21:49
simple EM rpc server
require 'rubygems'
require 'eventmachine'
require 'socket'
module RPCServer
include EM::P::ObjectProtocol
def post_init
@obj = Hash.new
end
def receive_object method