Skip to content

Instantly share code, notes, and snippets.

@cevaris
cevaris / struct_as_map_key.go
Last active October 20, 2023 03:18
Golang: Using structs as key for Maps
package main
import "fmt"
type A struct {
a, b int
}
func MapStructValAsKey(){
// Notice: We are using value of `A`, not `*A`
@cevaris
cevaris / generate_key.sh
Last active October 17, 2023 17:42
Sign and Verify using Python pycrypto
#!/usr/bin/env bash
# Generate RSA private key
openssl genrsa -out private_key.pem 1024
@cevaris
cevaris / float.go
Created March 9, 2015 14:09
Golang float64 equality esitimation
var EPSILON float64 = 0.00000001
func floatEquals(a, b float64) bool {
if ((a - b) < EPSILON && (b - a) < EPSILON) {
return true
}
return false
}
@cevaris
cevaris / spinner.py
Created November 12, 2015 16:45 — forked from anonymous/spinner.py
Simple Python CLI Spinner
#!/usr/bin/env python
import itertools
import sys
import time
import threading
class Spinner(object):
spinner_cycle = itertools.cycle(['-', '/', '|', '\\'])
@cevaris
cevaris / survey-to-json-csv.py
Created August 27, 2021 16:07
DRAFT: B2B records dump w/ survey transformation
#!/usr/bin/env python3
import json
import os
import sys
class UserRecord(object):
user_id: str
first_name: str
last_name: str
@cevaris
cevaris / samplf.sh
Created March 11, 2015 14:58
Naive sampling of file for bash/zsh
# Sample file
samplef() {
# set -x
if [ -z "${1}" ]; then
echo 'Error: Missing file path'
echo
echo 'Usage:'
echo 'samplef <FILEPATH> <SAMPLE_SIZE>'
echo
echo 'Optional paramters: <SAMPLE_SIZE>, default is 0.1'
@cevaris
cevaris / snake_to_hyphen_case.py
Created January 4, 2021 00:53
snake_to_hyphen_case.py
input = 'this_is_a_test_string'
output = ''
for i in range(0, len(input)):
char = input[i]
if char == '_':
output += '-'
else:
output += char
@cevaris
cevaris / data.js
Created November 19, 2020 23:39
custom Prototype iterator
function Data() {
this.data = [1, 2, 3, 4, 5];
}
Data.prototype[Symbol.iterator] = function* () {
for (const e of this.data) {
yield e;
}
};
@cevaris
cevaris / linkList.js
Last active November 4, 2020 14:15
LinkList iterator method
@cevaris
cevaris / stopwatch.ts
Last active June 3, 2020 21:22
Simple stopwatch that measures overall time.
interface StopwatchResults {
startDate: Date
endDate: Date
latencyMs: number
}
class Stopwatch {
private startDate?: Date
private endDate?: Date