Skip to content

Instantly share code, notes, and snippets.

View HusseinMorsy's full-sized avatar

Hussein Morsy HusseinMorsy

  • morSystem GmbH
  • Düsseldorf, Germany
View GitHub Profile
#!/usr/bin/env bash
# Abort sign off on any error
set -e
# Start the benchmark timer
SECONDS=0
# Repository introspection
OWNER=$(gh repo view --json owner --jq .owner.login)
@peterc
peterc / perceptron.rb
Created June 7, 2023 20:30
Basic implementation of a perceptron in Ruby
class Perceptron
def initialize(inputs, bias = 0.0)
@weights = Array.new(inputs.keys.first.size) { rand }
@inputs = inputs
@bias = bias
end
def run(inputs)
z = inputs.zip(@weights).map { |i, w| i * w }.reduce(:+) + @bias
1.0 / (1.0 + Math.exp(-z))
# Rails production setup via SQLite3 made durable by https://litestream.io/
# Copy this to Dockerfile on a fresh rails app. Deploy to fly.io or any other container engine.
#
# try locally: docker build . -t rails && docker run -p3000:3000 -it rails
#
# in production you might want to map /data to somewhere on the host,
# but you don't have to!
#
FROM ruby:3.0.2
function CopyButton({ value }) {
let [copied, setCopied] = React.useState();
let hydrated = usePageIsHydrated();
React.useEffect(() => {
let id = setTimeout(() => setCopied(false), 2000);
return () => clearTimeout(id);
}, [copied]);
return (
<button
@dhh
dhh / Gemfile
Created June 24, 2020 22:23
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@dhh
dhh / tracker_blocking.rb
Last active June 30, 2024 14:35
Current list of spy pixels named'n'shamed in HEY, as of April 23, 2020
module Entry::TrackerBlocking
extend ActiveSupport::Concern
included do
has_many :blocked_trackers
end
email_service_blockers = {
"ActiveCampaign" => /lt\.php(.*)?l\=open/,
"AWeber" => "openrate.aweber.com",
@kentcdodds
kentcdodds / autofill-feedback-email.js
Last active April 19, 2023 04:59
I use this to automatically fill in email addresses in feedback forms throughout workshop material
#!/usr/bin/env node
const path = require('path')
const inquirer = require('inquirer')
const replace = require('replace-in-file')
const isCI = require('is-ci')
const spawn = require('cross-spawn')
const fileGlob = process.argv[2] || 'src/**/*.*'
const files = path.isAbsolute(fileGlob)
function createStringBuilder() {
let str = '';
return function self(key) {
switch (key) {
case 'append':
return (s) => {
str += s;
return self;
};
case 'toString':
@keimlink
keimlink / nvm_vs_volta.md
Last active June 3, 2024 09:57
nvm vs Volta

nvm vs Volta

A comparison of nvm and Volta to manage Node.js projects (without Yarn).

Bootstrapping a Project

Bootstrapping a Project with nvm

nvm install
@alexanderkjeldaas
alexanderkjeldaas / setup-k3s-on-hetzner.sh
Last active January 10, 2024 19:07
Setup k3s on Hetzner with CSI drivers
#!/bin/bash
LOCATION=${HCLOUD_LOCATION:-nbg1-dc3}
if [ -z "$HCLOUD_TOKEN" ]; then
echo "You need to set HCLOUD_TOKEN to an Hetzner API token!";
exit 1
fi
if [ -z "$SSH_KEY" ]; then