Skip to content

Instantly share code, notes, and snippets.

View OldhamMade's full-sized avatar

OldhamMade OldhamMade

  • Amsterdam, NL
View GitHub Profile
@gcauchon
gcauchon / !Protocol for external APIs
Last active September 8, 2023 15:47
Using protocol for external APIs
iex(1)> Foo.Correspondence.validate_number("234-555-6789")
{:ok, "Verizon Wireless", "mobile"}
# This Crystal source file is a multiple threaded implementation to perform an
# extremely fast Segmented Sieve of Zakiya (SSoZ) to find Twin Primes <= N.
# Inputs are single values N, or ranges N1 and N2, of 64-bits, 0 -- 2^64 - 1.
# Output is the number of twin primes <= N, or in range N1 to N2; the last
# twin prime value for the range; and the total time of execution.
# This code was developed on a System76 laptop with an Intel I7 6700HQ cpu,
# 2.6-3.5 GHz clock, with 8 threads, and 16GB of memory. Parameter tuning
# probably needed to optimize for other hardware systems (ARM, PowerPC, etc).
@keathley
keathley / .credo.exs
Last active December 30, 2023 16:13
Keathley's credo file
# This file contains the configuration for Credo and you are probably reading
# this after creating it with `mix credo.gen.config`.
#
# If you find anything wrong or unclear in this file, please report an
# issue on GitHub: https://github.com/rrrene/credo/issues
#
%{
#
# You can have as many configs as you like in the `configs:` field.
configs: [
defmodule Web do
require Logger
@behaviour :elli_handler
def handle(r, _args) do
Router.handle(:elli_request.method(r), :elli_request.path(r), r)
rescue
exception ->
Logger.error(inspect(exception))
@JoachimL
JoachimL / barcodereader.py
Last active November 8, 2022 07:33
Python USB barcode reader
import evdev
from evdev import *
from azure.storage.queue import QueueService, QueueMessageFormat
import threading
import time
from queue import *
import datetime
# responsible for uploading the barcodes to the azure storage queue.
class BarcodeUploader:

FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.


Effective Engineer - Notes

What's an Effective Engineer?

@svanoort
svanoort / gcsettings.sh
Last active December 20, 2023 02:27
Blessed GC settings for big servers
# Base settings and GC logging
-server -XX:+AlwaysPreTouch # First should be default, but we make it explicit, second pre-zeroes memory mapped pages on JVM startup -- improves runtime performance
# -Xloggc:gc-%t.log # CUSTOMIZE LOCATION HERE - $path/gc-%t.log -- the %t in the gc log file path is so we get a new file with each JVM restart
-XX:NumberOfGCLogFiles=5 -XX:+UseGCLogFileRotation -XX:GCLogFileSize=20m # Limits the number of files, logs to folder
-XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintHeapAtGC -XX:+PrintGCCause
-XX:+PrintTenuringDistribution -XX:+PrintReferenceGC -XX:+PrintAdaptiveSizePolicy # gather info on object age & reference GC time for further tuning if needed.
# G1 specific settings -- probably should be default for multi-core systems with >2 GB of heap (below that, default is probably fine)
-XX:+UseG1GC
-XX:+UseStringDeduplication
@jarednorman
jarednorman / react-phantomjs.markdown
Created February 22, 2016 08:05
Running React on PhantomJS

Running React on PhantomJS

I ran into an issue getting a simple Capybara/Poltergeist feature test suite running against a site that used React.js. The following failure was bubbling up to RSpec.

Failures:
@gbaman
gbaman / HowToOTG.md
Last active September 16, 2024 09:47
Simple guide for setting up OTG modes on the Raspberry Pi Zero

Raspberry Pi Zero OTG Mode

Simple guide for setting up OTG modes on the Raspberry Pi Zero - By Andrew Mulholland (gbaman).

The Raspberry Pi Zero (and model A and A+) support USB On The Go, given the processor is connected directly to the USB port, unlike on the B, B+ or Pi 2 B, which goes via a USB hub.
Because of this, if setup to, the Pi can act as a USB slave instead, providing virtual serial (a terminal), virtual ethernet, virtual mass storage device (pendrive) or even other virtual devices like HID, MIDI, or act as a virtual webcam!
It is important to note that, although the model A and A+ can support being a USB slave, they are missing the ID pin (is tied to ground internally) so are unable to dynamically switch between USB master/slave mode. As such, they default to USB master mode. There is no easy way to change this right now.
It is also important to note, that a USB to UART serial adapter is not needed for any of these guides, as may be documented elsewhere across the int

module Indexable(T)
def threadpool_map(workers : Int = 8, chunk_size : Int? = nil, &func : T -> R) forall T, R
mutex = Thread::Mutex.new
cs = chunk_size || (self.size**0.5).ceil.to_i
Array(R).build(self.size) do |result|
index = 0
threads = Array.new(workers) {
Thread.new do
a = b = 0
loop do