Skip to content

Instantly share code, notes, and snippets.

View gavi's full-sized avatar
🎯
Focusing

Gavi Narra gavi

🎯
Focusing
View GitHub Profile
@gavi
gavi / Render.swift
Created June 17, 2022 18:19
Draw by overriding draw on UIView
import UIKit
import PlaygroundSupport
class Rectangle:UIView{
override func draw(_ rect: CGRect) {
let path = UIBezierPath(rect: rect)
path.move(to: CGPoint(x:0,y:rect.height))
path.addLine(to: CGPoint(x:rect.width/2,y:rect.height/1.4))
import MapKit
import SwiftUI
import PlaygroundSupport
struct ContentView:View{
var body:some View{
VStack{
Text("Hello, World")
MapView()
@gavi
gavi / MapkitSwiftUI.swift
Last active July 9, 2020 13:43
A quick playground example of SwiftUI with Mapkit. UIViewRepresentable is used
import MapKit
import SwiftUI
import PlaygroundSupport
struct ContentView:View{
var body:some View{
VStack{
Text("Hello, World")
MapView()
@gavi
gavi / SBRabbit.cs
Created December 28, 2019 17:11
Rabbit MQ publish and subscribe basic
using System;
using System.Text;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
namespace SBRabbit{
class Program{
static void Usage(){
Console.WriteLine("SBRabbit <publish|susbscribe>");
}
@gavi
gavi / ssl_binding.ps1
Created January 27, 2019 03:07
Bind SSL on Windows to a specific IP address and Certificate Thumbprint
function AddSSLBinding($fqdn,$ip,$thumbprint){
$cert = Get-ChildItem Cert:\LocalMachine\My\$($thumbprint)
New-WebBinding -Name $fqdn -IPAddress "$($ip)" -Port 443 -Protocol "https" -HostHeader $fqdn
$bind = Get-WebBinding -Name $fqdn -Protocol https
$bind.AddSslCertificate($cert.GetCertHashString(), "my")
}
#Usage Example
AddSSLBinding "test.domain.com" "10.0.0.1" "12344979A469750712B5EAC6168D85EC02E053FC"
@gavi
gavi / hostentry.ps1
Created January 18, 2019 21:04
Add host entry to windows host file
function AddHostEntry($fqdn){
$Pattern = '^(?<IP>\d{1,3}(\.\d{1,3}){3})\s+(?<Host>.+)$'
$File = "$env:SystemDrive\Windows\System32\Drivers\etc\hosts"
$Entries = @()
$found = $false
(Get-Content -Path $File) | ForEach-Object {
If ($_ -match $Pattern) {
#Write-Host "$($Matches.IP),$($Matches.Host)" -ForegroundColor Green
@gavi
gavi / webconfig.ps1
Created January 17, 2019 16:40
Add a connectionString to Web.config
function AddAttribute([System.Xml.XmlNode] $node, $name , $value){
$attrib = $node.OwnerDocument.CreateAttribute($name)
$attrib.Value = $value
$node.Attributes.Append($attrib)
}
function AddConnectionString($webconfigFile, $name, $connectionString){
[xml]$document = Get-Content $webconfigFile
$configElement = $document.SelectSingleNode("configuration")
$connectionStringsElement = $configElement.SelectSingleNode("connectionStrings")
@gavi
gavi / mojave.sh
Created June 11, 2018 18:16
macOS Mojave 10.4 Beta to ISO for installing on VMWare Fusion
hdiutil create -o /tmp/mojave.cdr.dmg -size 7130m -layout SPUD -fs HFS+J
hdiutil attach /tmp/mojave.cdr.dmg -noverify -mountpoint /Volumes/install_build
sudo /Applications/Install\ macOS\ 10.14\ Beta.app/Contents/Resources/createinstallmedia --volume /Volumes/install_build
hdiutil detach /Volumes/Install\ macOS\ 10.14\ Beta
mv /tmp/mojave.cdr.dmg ~/Desktop/InstallSystem.dmg
hdiutil convert ~/Desktop/InstallSystem.dmg -format UDTO -o ~/Desktop/mojave.iso
mv ~/Desktop/mojave.iso.cdr ~/Desktop/mojave.iso
rm ~/Desktop/InstallSystem.dmg
@gavi
gavi / coremltools.py
Created July 17, 2017 20:22
Convert Scikit-Learn model to CoreML .mlmodel file
#Now lets export to .mlmodel format
import coremltools
coreml_model = coremltools.converters.sklearn.convert(clf,['Sepal.Length','Sepal.Width','Petal.Length','Petal.Width'],'Species')
coreml_model.author = 'Gavi Narra'
coreml_model.license = 'BSD'
coreml_model.short_description = 'Predicts the iris species provided the sepal length, sepal width, petal length and petal width.'
coreml_model.save('iris.mlmodel')
@gavi
gavi / iris.py
Created July 17, 2017 20:06
Basic scikit learn with IRIS data
from sklearn import datasets
from sklearn.ensemble import RandomForestClassifier
import coremltools
iris = datasets.load_iris()
clf = RandomForestClassifier()
clf.fit(iris.data, iris.target_names[iris.target])
#Test to see if it is working correctly
print(list(clf.predict(iris.data[:3])))
print(list(clf.predict([[ 5.1,3.5,1.4,0.2]])))