This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
# Based on tornado.ioloop.IOLoop.instance() approach. | |
# See https://github.com/facebook/tornado | |
class SingletonMixin(object): | |
__singleton_lock = threading.Lock() | |
__singleton_instance = None | |
@classmethod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Simple demonstration of how to implement Server-sent events (SSE) in Python | |
using Bottle micro web-framework. | |
SSE require asynchronous request handling, but it's tricky with WSGI. One way | |
to achieve that is to use gevent library as shown here. | |
Usage: just start the script and open http://localhost:8080/ in your browser. | |
Based on: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
print(f(true).map((value) => value + 1)); | |
print(f(false).map((value) => value + 1)); | |
print([1, 2, 3].map((value) => "x ${value + 1}")); | |
print([].map((value) => value + 1)); | |
} | |
// Methods like | |
// map, flatMap / expand, filter / where, firstWhere, reduce, fold |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() async { | |
await variant1(); | |
variant2(); | |
print("xxx"); | |
} | |
Future<void> variant1() async { | |
final result = await y(); | |
// async gap | |
print("y: $result"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based on https://github.com/lima-vm/lima/blob/943c90b13e38be32777b8f25be17c2491bb1421f/examples/podman.yaml | |
# | |
# Allows connections to ports 80, 443 through non-loopback interfaces. | |
# Example to use Podman instead of containerd & nerdctl | |
# $ limactl start ./podman.yaml | |
# $ limactl shell podman podman run -it -v $HOME:$HOME --rm docker.io/library/alpine | |
# To run `podman` on the host (assumes podman-remote is installed): | |
# $ export CONTAINER_HOST=$(limactl list podman --format 'unix://{{.Dir}}/sock/podman.sock') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import SystemConfiguration.CaptiveNetwork | |
func getWiFiSsid() -> String? { | |
var ssid: String? | |
if let interfaces = CNCopySupportedInterfaces() as NSArray? { | |
for interface in interfaces { | |
if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? { | |
ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CircularQueue.h | |
// | |
// Created on 9/21/13. | |
// | |
#import <Foundation/Foundation.h> | |
@interface CircularQueue : NSObject <NSFastEnumeration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Resample into segments of random length | |
// Run over primitives | |
float seed = chf("seed"); | |
float seg_len_min = chi("seg_len_min"); | |
float seg_len_max = chi("seg_len_max"); | |
float seg_padding = chf("padding"); | |
if (seg_len_min <= 0 || seg_len_max < seg_len_min || seg_padding < 0) { | |
error("Make sure 0 < seg_len_min <= seg_len_max and 0 <= seg_padding"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
// MARK: - Specification | |
protocol ViewType { | |
associatedtype ViewModel: ViewModelType | |
var viewModel: ViewModel { get } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol ServiceLocator { | |
func getService<T>() -> T? | |
} | |
final class LazyServiceLocator: ServiceLocator { | |
/// Registry record | |
enum RegistryRec { | |
case Instance(Any) |
NewerOlder