Skip to content

Instantly share code, notes, and snippets.

@rabimba
rabimba / vpn-fix.sh
Created January 20, 2023 17:10
AnyConnect DNS resolution fix for WSL2
#!/bin/bash
echo "Getting current DNS servers, this takes a couple of seconds"
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command '
$ErrorActionPreference="SilentlyContinue"
Get-NetAdapter -InterfaceDescription "Cisco AnyConnect*" | Get-DnsClientServerAddress | Select -ExpandProperty ServerAddresses
Get-NetAdapter | ?{-not ($_.InterfaceDescription -like "Cisco AnyConnect*") } | Get-DnsClientServerAddress | Select -ExpandProperty ServerAddresses
' | \
awk 'BEGIN { print "# Generated by vpn-fix on", strftime("%c"); print } { print "nameserver", $1 }' | \
@rabimba
rabimba / mosaic.py
Created April 4, 2020 20:52
create picture montages
import sys
import os
from PIL import Image
from multiprocessing import Process, Queue, cpu_count
TILE_SIZE = 100
TILE_MATCH_RES = 25
ENLARGEMENT = 10
@rabimba
rabimba / manifest.webmanifest
Created January 24, 2020 03:24
Guru Manifest
{
"dir" : "ltr",
"lang" : "bn",
"name" : "গুরুচন্ডালি",
"scope" : "/",
"display" : "browser",
"start_url" : "https://www.guruchandali.com/",
"short_name" : "গুরুচন্ডালি",
"theme_color" : "transparent",
"description" : "",
@rabimba
rabimba / anchor.py
Created October 29, 2018 07:21
Brisk Anchor test
import cv2 # OpenCV
# 1. Load the original image
img = cv2.imread('paris.jpg')
# Convert the image to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# 2. Create BRISK algorithm
# OpenCV default threshold = 30, octaves = 3
# Using 4 octaves as cited as typical value by the original paper by Leutenegger et al.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>DQ Test</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
func fetchConfig() {
var expirationDuration: Double = 3600
// If in developer mode cacheExpiration is set to 0 so each fetch will retrieve values from
// the server.
if (self.remoteConfig.configSettings.isDeveloperModeEnabled) {
expirationDuration = 0
}
// cacheExpirationSeconds is set to cacheExpiration here, indicating that any previously
// fetched and cached config would be considered expired because it would have been fetched
func imagePickerController(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [String : Any]) {
picker.dismiss(animated: true, completion:nil)
guard let uid = FIRAuth.auth()?.currentUser?.uid else { return }
// if it's a photo from the library, not an image from the camera
if #available(iOS 8.0, *), let referenceURL = info[UIImagePickerControllerReferenceURL] {
let assets = PHAsset.fetchAssets(withALAssetURLs: [referenceURL as! URL], options: nil)
let asset = assets.firstObject
asset?.requestContentEditingInput(with: nil, completionHandler: { [weak self] (contentEditingInput, info) in
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// Dequeue cell
let cell = self.clientTable .dequeueReusableCell(withIdentifier: "tableViewCell", for: indexPath)
// Unpack message from Firebase DataSnapshot
let messageSnapshot: FIRDataSnapshot! = self.messages[indexPath.row]
let message = messageSnapshot.value as! Dictionary<String, String>
let name = message[Constants.MessageFields.name] as String!
if let imageURL = message[Constants.MessageFields.imageURL] {
if imageURL.hasPrefix("gs://") {
FIRStorage.storage().reference(forURL: imageURL).data(withMaxSize: INT64_MAX){ (data, error) in
deinit {
self.ref.child("messages").removeObserverWithHandle(_refHandle)
}
func configureDatabase() {
ref = FIRDatabase.database().reference()
// Listen for new messages in the Firebase database
_refHandle = self.ref.child("messages").observe(.childAdded, with: { [weak self] (snapshot) -> Void in
guard let strongSelf = self else { return }
override func viewDidAppear(_ animated: Bool) {
if let user = FIRAuth.auth()?.currentUser {
self.signedIn(user)
}
}
@IBAction func didTapSignIn(_ sender: AnyObject) {
// Sign In with credentials.
guard let email = emailField.text, let password = passwordField.text else { return }
FIRAuth.auth()?.signIn(withEmail: email, password: password) { (user, error) in