Skip to content

Instantly share code, notes, and snippets.

View dlcmh's full-sized avatar
💭
Hybridizing...

David Chin dlcmh

💭
Hybridizing...
View GitHub Profile
@noelbundick
noelbundick / README.md
Created October 14, 2021 16:15
Optimizing Rust container builds

Optimizing Rust container builds

I'm a Rust newbie, and one of the things that I've found frustrating is that the default docker build experience is extremely slow. As it downloads crates, then dependencies, then finally my app - I often get distracted, start doing something else, then come back several minutes later and forget what I was doing

Recently, I had the idea to make it a little better by combining multistage builds with some of the amazing features from BuildKit. Specifically, cache mounts, which let a build container cache directories for compilers & package managers. Here's a quick annotated before & after from a real app I encountered.

Before

This is a standard enough multistage Dockerfile. Nothing seemingly terrible or great here - just a normal build stage, and a smaller runtime stage.

@ciiiii
ciiiii / Dockerfile
Last active January 21, 2024 12:30
Postgresql for Chinese Full-Text Search.中文全文搜索
# If you don‘t want to build it youself, you can try `docker pull killercai/postgres`.
FROM healthcheck/postgres:latest
# China debian mirror
RUN sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN apt-get clean && apt-get update
RUN apt-get install -y wget git build-essential libpq-dev python-dev postgresql-server-dev-all
# SCWS (Simple Chinese Word Segmentation library)
RUN cd /tmp && wget -q -O - http://www.xunsearch.com/scws/down/scws-1.2.1.tar.bz2 | tar xjf - && cd scws-1.2.1 && ./configure && make install
# zhpaser (postgres plugin)
@maxivak
maxivak / __readme.md
Last active January 19, 2024 15:00
Load code in libraries in Rails 5

Load lib files in production (Rails 5)

If you have your code defined in classes in lib/ folder you may have problems to load that code in production.

Autoloading is disabled in the production environment by default because of thread safety.

Change config/application.rb:

    config.autoload_paths << Rails.root.join("lib")
 config.eager_load_paths &lt;&lt; Rails.root.join("lib")
@thebucknerlife
thebucknerlife / authentication_with_bcrypt_in_rails_4.md
Last active January 17, 2024 23:54
Simple Authentication in Rail 4 Using Bcrypt

#Simple Authentication with Bcrypt

This tutorial is for adding authentication to a vanilla Ruby on Rails app using Bcrypt and has_secure_password.

The steps below are based on Ryan Bates's approach from Railscast #250 Authentication from Scratch (revised).

You can see the final source code here: repo. I began with a stock rails app using rails new gif_vault

##Steps

@aboisvert
aboisvert / avxcount.nim
Last active August 21, 2023 10:59
Nim port of Daniel Lemire's fast newline count `avxcount` .
# Nim port of Daniel Lemire's fast newline count `avxcount`
#
# See https://lemire.me/blog/2017/02/14/how-fast-can-you-count-lines/
# https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/blob/master/2017/02/14/newlines.c
import os, memfiles, times, strutils
{.passc: "-march=native".}
{.pragma: imm, header:"immintrin.h".}
@schabluk
schabluk / ract-dropzone-image.js
Created February 10, 2017 11:55
React-Dropzone get image width, height and base64 data
onDrop = (acceptedFiles, rejectedFiles) => {
const file = acceptedFiles.find(f => f)
const i = new Image()
i.onload = () => {
let reader = new FileReader()
reader.readAsDataURL(file)
reader.onload = () => {
console.log({
src: file.preview,
@schollz
schollz / fetch2.js
Created August 27, 2017 15:16
Use Puppeteer to download a webpage after its been processed by javascript
// save as index.js
// npm install https://github.com/GoogleChrome/puppeteer/
// node index.js URL
const puppeteer = require('puppeteer');
(async () => {
const url = process.argv[2];
const browser = await puppeteer.launch();
// use tor
//const browser = await puppeteer.launch({args:['--proxy-server=socks5://127.0.0.1:9050']});
@rrafal
rrafal / pgx_json.go
Created March 31, 2016 00:03
Use JSON column with golang pgx driver.
package main
import (
"fmt"
"encoding/json"
"github.com/jackc/pgx"
"log"
)
var schema = `
@radik909
radik909 / fibonacci.exs
Last active November 20, 2022 12:33
Find first n fibonacci numbers (using Stream in Elixir)
defmodule Fibonacci do
def run(num) when num > 0 do
Stream.unfold({1, 1}, fn {a, b} ->
{a, {b, a + b}}
end)
|> Enum.take(num)
end
end
IO.gets("Enter the limit: ")
@0b10011
0b10011 / cargo
Created November 22, 2019 19:23
A dockerized drop-in replacement for `cargo` that supports caching.
#!/bin/bash
# This is a drop-in replacement for `cargo`
# that runs in a Docker container as the current user
# on the latest Rust image
# and saves all generated files to `./cargo/` and `./target/`.
#
# Be sure to make this file executable: `chmod +x ./cargo`
#
# # Examples