This file contains hidden or 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
from datetime import datetime | |
from enum import Enum as RegularEnum | |
from enum import auto | |
from sqlalchemy import Column, DateTime | |
from sqlalchemy import Enum as DatabaseEnum | |
from sqlalchemy import ForeignKey, Integer, String, event | |
from sqlalchemy.engine import create_engine | |
from sqlalchemy.orm import declarative_base, relationship, sessionmaker |
This file contains hidden or 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
var multFour: [Int: Int] = [:] | |
for i in 1...3 { | |
multFour[i] = i * 4 | |
} | |
typealias AnswerItem = Dictionary<Int, Int>.Element | |
typealias AnswerTuple = (Int, Int) | |
let sortedMultFour: [AnswerItem] = multFour.sorted { x, y in x.key < y.key } |
This file contains hidden or 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
# Colab -> https://goo.gle/tfw-sarcembed | |
# GitHub -> https://goo.gle/2PH90ea | |
import json | |
with open("sarcasm.json", "r") as f: | |
datastore = json.load(f) | |
sentences = [] | |
labels = [] | |
for item in datastore: |
This file contains hidden or 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
/// See link more details: | |
/// https://doc.rust-lang.org/book/ch04-01-what-is-ownership.html | |
fn main() { | |
// String is made up of the following: | |
// - pointer to string contents | |
// - length | |
// - capacity | |
let s1 = String::from("hello"); | |
// immutable transfer from s1 to s2 |
This file contains hidden or 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
//! A module with classic algorithms from CS 101 classes. | |
//! Consider using this as a way to learn how Rust works | |
//! in general while solving safe + simple problems. | |
/// Returns a `Result` from computing factorial | |
/// | |
/// # Arguments | |
/// | |
/// * `n` - An integer | |
pub fn fact(n: i32) -> Result<i32, i32> { |
This file contains hidden or 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
# Run `git pull` for every repo under a path | |
function gpull() { | |
# shellcheck disable=SC2156 | |
find "${1:-.}" -type d -name ".git" -exec bash -c ' | |
cd {}/../ | |
dir="$(pwd)" | |
if grep -qs "remote" .git/config; then | |
echo "= pull $dir" | |
git pull -q | |
else |
This file contains hidden or 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
def approve(whitelist): | |
"""Bind whitelist arg to wrapper""" | |
def wrapper(func): | |
"""Bind old func to guard""" | |
def guard(*args, **kwargs): | |
"""Check if 'name' keyword matches whitelist""" | |
name = kwargs.get("name") | |
if name in whitelist: | |
print(f"=== approved {name}") | |
func(*args, **kwargs) |
This file contains hidden or 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
from datetime import datetime | |
from random import randint | |
from time import sleep | |
from flask import Flask, jsonify, render_template | |
app = Flask(__name__) | |
This file contains hidden or 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
function ssh_tunnel() { | |
target_host="$1" | |
target_port="$2" | |
tunnel_host="$3" | |
source_port="$4" | |
[[ `ps axu | grep $target_port | grep ssh` ]] && return | |
ssh -Nf -L "$source_port:$target_host:$target_port" "$tunnel_host" | |
} |
This file contains hidden or 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
#!/bin/bash | |
# kafka-demo.sh: A playground for running Kafka on a Docker container | |
# https://www.tutorialspoint.com/apache_kafka/apache_kafka_basic_operations.htm | |
# Initialization step | |
# openjdk:8 image uses the following software: | |
# Java 1.8.0_212 and Debian 9 (stretch) | |
docker run --rm -it --name kafka openjdk:8 bash | |
# All the commands below are run within the Docker container |