Skip to content

Instantly share code, notes, and snippets.

@scpike
scpike / incompat_71.rb
Last active February 28, 2024 16:26
Check for silent gem incompatibilities in Rails 7.1
#!/usr/bin/env ruby
# Run like `ruby incompat_71.rb ~/path/to/Gemfile.lock`
# From the team at infield.ai
#
PACKAGES = [['activerecord-import', '1.5.0'],
['anycable-rails', '1.4.1'],
['blazer', '3.0.1'],
['bullet', '7.1.2'],
['data_migrate', '9.2.0'],
['database_cleaner-active_record', '2.1.0'],
(function(x) {
if (x.length > 0) {
return "'(" + x.split("\n").join("|") + ")'"
}
})
(function(x) {
return x;
})
# String#to_i converts a string to an integer:
# "42".to_i # 42
# "0".to_i # 0
#
# Implement a new function atoi(s) which takes a string and converts it to an integer without using to_i:
# atoi("42") # 42
# atoi("0") # 0
#
def atoi(s)
-1 # not the right answer
@scpike
scpike / README.md
Created March 2, 2016 16:21 — forked from renchap/README.md
One-line certificate generation/renews with Letsencrypt and nginx

Prerequisites : the letsencrypt CLI tool

This method allows your to generate and renew your Lets Encrypt certificates with 1 command. This is easily automatable to renew each 60 days, as advised.

You need nginx to answer on port 80 on all the domains you want a certificate for. Then you need to serve the challenge used by letsencrypt on /.well-known/acme-challenge. Then we invoke the letsencrypt command, telling the tool to write the challenge files in the directory we used as a root in the nginx configuration.

I redirect all HTTP requests on HTTPS, so my nginx config looks like :

server {
@scpike
scpike / dedupe.js
Last active November 23, 2015 03:50
deduplicate some names
// http://stackoverflow.com/questions/18233874/get-all-the-combinations-of-n-elements-of-multidimensional-array
function getCombinations(arr, n) {
if(n == 1)
{
var ret = [];
for(var i = 0; i < arr.length; i++)
{
ret.push([arr[i]]);
}
return ret;
-> (x) do
x.split("\n").reject { |l| l.to_s.strip == '' }.join("\n")
end
@scpike
scpike / sortlines.rb
Created October 27, 2015 02:05
sortlines
-> (s) do
s.split("\n").sort.join("\n")
end
@scpike
scpike / tokens.js
Last active October 26, 2015 14:43
(function (x) {
var tokens = x.split(/[\s]/mi);
var occ = {};
tokens.forEach(function(tok) {
var clean = tok.toLowerCase().trim().replace(/[^\w\d\/]/, '');
if (occ[clean]) {
occ[clean] += 1;
} else {
occ[clean] = 1;
}
@scpike
scpike / catsql.js
Created October 20, 2015 20:16
Combine a list of numbers for a big `in ()` statement
(function(x) {
if (x.length > 0) {
return "(" + x.split("\n").join(',') + ")"
}
})