Skip to content

Instantly share code, notes, and snippets.

View MaxPleaner's full-sized avatar

Max Pleaner MaxPleaner

View GitHub Profile

>! spoiler

@MaxPleaner
MaxPleaner / wip.js
Created April 6, 2017 19:38
WIP webpack plugin
function MergeGifPlugin(options) {
}
MergeGifPlugin.prototype.apply = function(compiler) {
compiler.plugin("emit", function(compilation, callback){
// console.log(compilation)
// console.log(compilation.missingDependencies)
console.dir(Object.keys(compilation.errors[0]))
console.log(compilation.errors[0].name)
console.log(compilation.errors[0].message)
})
@MaxPleaner
MaxPleaner / read-md.fish
Created March 29, 2017 21:18
read formatted markdown file from CLI
# this is a fish function
# if using fish, add this to a new file at ~/.config/fish/functions/read-md.fish
# otherwise, use line 2 only and replace $argv with a markdown file path.
function read-md
pandoc $argv | lynx -stdin
end
# source:
# http://unix.stackexchange.com/a/120519/65890
@MaxPleaner
MaxPleaner / record-out.fish
Created March 29, 2017 20:40
record system output directly (without microphone)
# note this is a fish function
# if you're using fish shell, create a new file called ~/.config/fish/functions/record-out.fish
# and copy this in there
#
# otherwise, just use line 2 and replace $argv with a filename such as out.mp3
function record-out
parec -d alsa_output.pci-0000_00_1b.0.analog-stereo.monitor | lame -r -V0 - $argv
end
@MaxPleaner
MaxPleaner / file.rb
Created March 17, 2017 06:21
example of closure in ruby when redefining value of self
def proc_with_closure(val)
Proc.new { other_function(val) }
end
class Tester
def self.other_function(val)
val * 2
end
end
@MaxPleaner
MaxPleaner / results.txt
Last active March 9, 2017 21:47
benchmark comparison of Sets vs Hashes
N = 10000000
SET INSERTION:
user system total real
13.080000 0.370000 13.450000 ( 13.453529)
HASH INSERTION:
user system total real
12.870000 0.330000 13.200000 ( 13.193739)
SET DELETION:
user system total real
@MaxPleaner
MaxPleaner / search.rb
Created February 17, 2017 23:25
codementor gist
def search(term)
@client.search({
index: "trends",
type: "trend",
body: {
suggest: {
name_suggest: {
prefix: term,
completion: {
field: "name_suggest"
@MaxPleaner
MaxPleaner / functions.fish
Last active January 19, 2017 17:44
top fish functions
# ~/.config/fish/functions/cfn.fish
# stands for "cat function" (shows a function definition)
function cfn
cat ~/.config/fish/functions/$argv.fish
end
# ~/.config/fish/functions/cfn.fish
# stands for "functions" (lists functions)
function fns
ls ~/.config/fish/functions
@MaxPleaner
MaxPleaner / preload_map.rb
Last active December 31, 2016 00:00
active record preload_map
class ActiveRecord::Query
def preload_map(association_name_sym)
preload(association_name_sym).map &association_name_sym
end
alias map_with_preload preload_map
end
@MaxPleaner
MaxPleaner / limit_threads.rb
Created December 30, 2016 03:35
limit total num threads
THREAD_LIMIT = ENV["THREAD_LIMIT"].to_i || 10
THREAD = {count: 0}
class TooManyThreadsError < StandardError; end
class Thread
def new(*args, &blk)
too_many_threads_error if THREAD[:count] > THREAD_LIMIT
THREAD["count"] += 1
super(*args, &->{blk.call; THREAD["count"] -= 1})