Skip to content

Instantly share code, notes, and snippets.

@sugarme
sugarme / main.go
Last active December 22, 2022 12:04
Golang - struct embedding and overriding a method of parent
package main
import (
"fmt"
)
// This is a demonstration of embedding struct and overriding
// a method of parent struct.
// https://go.dev/play/p/nIdwUV8Qlaj
@sugarme
sugarme / code-server-post-start.sh
Last active December 26, 2022 08:42
Shell script for code-server post start installation: Go, NeoVim,
#!/bin/bash
sudo su
apt update
apt -y install wget zip build-essential
# Install Go 1.19.4
wget https://go.dev/dl/go1.19.4.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.19.4.linux-amd64.tar.gz
exit
#!/bin/bash
GOTCH_VERSION="${GOTCH_VER:-v0.3.8}"
CUDA_VERSION="${CUDA_VER:-10.1}"
GOTCH_PATH="$GOPATH/pkg/mod/github.com/sugarme/gotch@$GOTCH_VERSION"
# Install gotch
#==============
echo "GOPATH:'$GOPATH'"
echo "GOTCH_VERSION: '$GOTCH_VERSION'"
@sugarme
sugarme / colab-setup.sh
Last active April 11, 2021 11:47
Basic colab setup for Go deep learning
#!/bin/bash
# Upgrade cmake and g++:
#=======================
apt remove --purge --auto-remove cmake
rm -rf /usr/lib/x86_64-linux-gnu/cmake
rm -rf /usr/local/bin/cmake
# cmake: ref https://apt.kitware.com/
apt-get install apt-transport-https ca-certificates gnupg software-properties-common wget
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null
@sugarme
sugarme / colab-ssh.sh
Last active December 16, 2022 03:43
script to ssh to google colab using tunnel ngrok
# Setup sshd
apt-get update
apt-get install -qq -o=Dpkg::Use-Pty=0 openssh-server pwgen > /dev/null
# create an account on ngrok if not already and copy the authtoken
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
unzip ngrok-stable-linux-amd64.zip
read -p 'Enter the authtoken from ngrok :' authtoken
./ngrok authtoken $authtoken
./ngrok tcp 22 &
@sugarme
sugarme / ngrxintro.md
Created January 8, 2018 12:29 — forked from btroncone/ngrxintro.md
A Comprehensive Introduction to @ngrx/store - Companion to Egghead.io Series

Comprehensive Introduction to @ngrx/store

By: @BTroncone

Also check out my lesson @ngrx/store in 10 minutes on egghead.io!

Update: Non-middleware examples have been updated to ngrx/store v2. More coming soon!

Table of Contents

@sugarme
sugarme / upload.component.ts
Created February 10, 2017 22:12 — forked from StephenFluin/upload.component.ts
Firebase Uploader Component with Angular 2
import { Component, Input } from '@angular/core';
import { Router } from '@angular/router';
import { AngularFire, FirebaseListObservable } from 'angularfire2';
import { Observable } from 'rxjs';
declare var firebase: any;
interface Image {
path: string;
@sugarme
sugarme / gist:29706b463b5af5dcb955b03c7d3ada9e
Created October 14, 2016 04:02 — forked from yetanotherchris/gist:4746671
Unique identifiers: Base62
public static string Base62Random()
{
int random = _random.Next();
return Base62ToString(random);
}
private static string Base62ToString(long value)
{
// Divides the number by 64, so how many 64s are in
// 'value'. This number is stored in Y.
@sugarme
sugarme / generate-pushid.js
Created October 12, 2016 23:26 — forked from mikelehen/generate-pushid.js
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/