Skip to content

Instantly share code, notes, and snippets.

View TonsOfFun's full-sized avatar
🏠
Working from home

Justin Bowen TonsOfFun

🏠
Working from home
View GitHub Profile
@palkan
palkan / index.html.erb
Created October 8, 2022 18:15
Action Cable image publisher
<div class="min-w-full flex flex-row">
<%= turbo_stream_from "demo" %>
<div id="demo"></div>
</div>
@whizzzkid
whizzzkid / XPS-15 9560 Getting Nvidia To Work on KDE Neon
Last active December 3, 2022 15:43
[XPS 15 Early 2017 9560 kabylake] Making Nvidia Drivers + (CUDA 8 / CUDA 9 / CUDA 9.1) + Bumblebee work together on linux ( Ubuntu / KDE Neon / Linux Mint / debian )
# Instructions for 4.14 and cuda 9.1
# If upgrading from 4.13 and cuda 9.0
$ sudo apt-get purge --auto-remove libcud*
$ sudo apt-get purge --auto-remove cuda*
$ sudo apt-get purge --auto-remove nvidia*
# also remove the container directory direcotory at /usr/local/cuda-9.0/
# Important libs required with 4.14.x with Cuda 9.X
$ sudo apt install libelf1 libelf-dev
@alexland
alexland / serialize-numpy-array.py
Last active November 28, 2023 07:12
serialize, persist, retrieve, and de-serialize a NumPy array as a binary string (any dimension, any dtype); exemplary use case: a web app calculates some result--eg, from a Machine Learning algorithm, using NumPy and the result is a NumPy array; it is efficient to just return that result to rather than persist the array then retrieve it via query
import time
import numpy as NP
from redis import StrictRedis as redis
# a 2D array to serialize
A = 10 * NP.random.randn(10000).reshape(1000, 10)
# flatten the 2D NumPy array and save it as a binary string
array_dtype = str(A.dtype)
@peterhellberg
peterhellberg / redis_connection_string.go
Created April 29, 2014 21:47
Parsing a Redis connection string for use with go-workers
package main
import (
"fmt"
"net/url"
"strings"
)
func main() {
s := "redis://username:password@my.host:6389/4?pool=25&process=2"
@straydogstudio
straydogstudio / circle_path
Last active September 11, 2018 21:18
Convert latitude/longitude pair with radius in meters to 16 sided polygon useful in GIS. Useful for converting a Google maps drawing manager circle into a polygon for storage in a GIS system. Implemented as a class method.
def self.circle_path(center, radius, complete_path = false)
# For increased accuracy, if your data is in a localized area, add the elevation in meters to r_e below:
r_e = 6378137.0
@@d2r ||= Math::PI/180
@@multipliers ||= begin
segments = 16
dRad = 2*Math::PI/segments
(segments + (complete_path ? 1 : 0)).times.map do |i|
rads = dRad*i
y = Math.sin(rads)
@springmeyer
springmeyer / install-mapnik-amazon-ami.sh
Last active January 6, 2024 15:06
Mapnik on Amazon Linux AMI (Fedora)
# http://aws.amazon.com/amazon-linux-ami/
# http://aws.amazon.com/amazon-linux-ami/faqs/
# Boot up a machine with at least 1.5 to 2 GB Ram
# login
chmod 600 key.pem
ssh -i key.pem ec2-user@ec2...compute.amazonaws.com
# update
@a-chernykh
a-chernykh / forum.rb
Created July 14, 2011 11:49
Mongoid counter cache
class Forum
include Mongoid::Document
include Mongoid::Timestamps
field :posts_count, :type => Integer, :default => 0
has_many_related :posts
end
@zefer
zefer / copy-s3-bucket.rb
Created April 4, 2011 11:24
Copy contents of an S3 bucket to a another bucket using an EC2 instance and a simple Ruby script. Useful for transferring large amounts of data and will work across geographic regions.
require 'rubygems'
require 'right_aws'
aws_access_key_id = 'your-access-key'
aws_secret_access_key = 'your-secret-key'
target_bucket = 'your-source-bucket'
destination_bucket = 'your-destination-bucket'
s3 = RightAws::S3Interface.new(aws_access_key_id, aws_secret_access_key)