Skip to content

Instantly share code, notes, and snippets.

View nicksieger's full-sized avatar

Nick Sieger nicksieger

View GitHub Profile
@matthewd
matthewd / db-switch.rb
Created April 1, 2021 05:50
bin/db-switch
#!/usr/bin/env ruby
require(Dir.pwd + "/config/environment")
ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env).each do |db_config|
ActiveRecord::Base.establish_connection(db_config.config)
context = ActiveRecord::Base.connection.migration_context
missing_migrations = []
@xmeng1
xmeng1 / wsl2-network.ps1
Created July 14, 2019 06:50
WSL2 Port forwarding port to linux
$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if( $found ){
$remoteport = $matches[0];
} else{
echo "The Script Exited, the ip address of WSL 2 cannot be found";
exit;
}
@semperos
semperos / div.clj
Last active September 11, 2015 22:12 — forked from gfmurphy/Div.hs
Readability
(defn digits
"Generate a list of digits contained in the number"
[number]
(loop [found-digits '() base (quot number 10) digit (rem number 10)]
(let [found-digits (conj found-digits (if (neg? digit) (- digit) digit))]
(if (zero? base)
found-digits
(recur found-digits (quot base 10) (rem base 10))))))
(defn divisible-digits
@glv
glv / _TheClojureStateMonad.md
Last active January 19, 2024 19:41
Comparing monadic and non-monadic styles for managing state in Clojure

The Clojure State Monad: A Non-Trivial Example

When I started writing this in early 2013, I intended it to be a series of blog posts about effective use of the state monad (and the `algo.monads` library in general) in Clojure. Along the way, I learned that `algo.monads` is both somewhat buggy and extremely slow, and I decided that the most effective way to use monads in Clojure was simply not to use them at all. Therefore, I abandoned work on the post. But it's still probably useful as a good way of explaining the state monad by example, so I've spruced the old draft up slightly and am posting it here.

TL;DR

There are too many monad tutorials, and not enough practical examples of solving real problems with monads. This article shows how to use

@john2x
john2x / 00_destructuring.md
Last active April 23, 2024 13:18
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences

@branneman
branneman / better-nodejs-require-paths.md
Last active April 27, 2024 04:16
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@relaxdiego
relaxdiego / graphite.md
Last active January 5, 2022 09:07 — forked from surjikal/graphite.md
Installing Graphite in OS X Mavericks

Follow these steps to install graphite on OS X Mavericks.

Prerequisites

  • Homebrew
  • Python 2.7
  • Git

Install dependencies

Install Cairo and friends

I'm writing in response to events that have recently come to light involving a sexual assault at a tech conference. Background information can be found [here][1], [here][2], and [here][3] as well as on twitter and google.


I've been watching this from the sidelines, and I've been wrestling with several questions that I can't seem to shake and that I really don't have answers to.

I wear many hats, both in the tech community and others. I'm a coder, a speaker, a user group organizer, a conference organizer, and even a boss. Each of those roles colors how I see this, but there's one role that is overpowering in my reaction.

See, I'm a Dad. A dad of two beautiful and innocent girls who are 3 and 2. They have their whole lives in front of them and so the questions I'm struggling with are:

@bokmann
bokmann / JRuby Awesome Performance
Last active August 31, 2023 07:32
brief summary of massive performance improvements with JRuby
# Thee will be more information here when I share the entire problem space I'm working on, but
# in short, this is preview material for my second talk in a series called "What Computer Scientists Know".
# The first talk is on recursion, and goes through several examples., leading up to a problem based
# on a simple puzzle that initial estimates based on performance of a previous puzzle would take years
# to solve on modern computers with the techniques shown in Ruby. That sets the stage for improving the
# performance of that problem with threading, concurrency, and related tuning.
#
# The second talk is on threading and concurrency, touching on algorithmic performance as well.
# Using some knowledge of the problem (board symmetry, illegal moves, etc), we reduce the problem space
# to about .5% of what we initially thought it was. Still, the initial single threaded solution took more
@nicksieger
nicksieger / thread_dump_on_quit.rb
Created August 29, 2012 14:38
kill -QUIT thread dump in Ruby. Seems like I need this and forget exactly how to do it.
trap("QUIT") do
Thread.list.each do |t|
$stderr.puts
$stderr.puts t.inspect
$stderr.puts t.backtrace.join("\n ")
end
end