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.

@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
@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)
@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".}
@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")
@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']});
@ethanhuang13
ethanhuang13 / detect-string-language.swift
Created March 23, 2017 03:46
Detect string language with Swift
//: Playground - noun: a place where people can play
//
// The result is not guaranteed to be accurate. Typically, the function requires 200-400 characters to reliably guess the language of a string.
// Reference: [CFStringTokenizerCopyBestStringLanguage(_:_:)](https://developer.apple.com/reference/corefoundation/1542136-cfstringtokenizercopybeststringl)
//
import Foundation
extension String {
func guessLanguage() -> String {
@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,
@sbalay
sbalay / FormNormalizeAndFormatValues.js
Last active July 11, 2022 05:02
Redux-form example with normalize and format
import React from 'react';
import { reduxForm, Field } from 'redux-form';
import { ScrollView, Text, TouchableOpacity } from 'react-native';
import moment from 'moment';
import MyTextInput from './MyTextInput';
/**
* Automatically adds the dashes required by the specified phone format and limits the input to ten characters
*/
@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: ")