Skip to content

Instantly share code, notes, and snippets.

View aleclarson's full-sized avatar

Alec Larson aleclarson

View GitHub Profile
@aleclarson
aleclarson / README.md
Last active May 1, 2024 00:23
rsync-backup

Selective backup for OSX

Using the awesome rsync-time-backup script by @laurent22, OSX users can selectively backup any directory on their computer.

  1. Download rsync_tmbackup.sh into your ~/bin directory:
wget https://raw.githubusercontent.com/laurent22/rsync-time-backup/master/rsync_tmbackup.sh -O ~/bin/rsync-backup
chmod +x ~/bin/rsync-backup
@aleclarson
aleclarson / splitEveryN.js
Last active January 11, 2018 23:30
Split a string every N characters (starting from the end)
function splitEveryN(str, n) {
const len = str.length
if (len > n) {
let i = len - n
const parts = []
while (true) {
parts.push(str.substr(i, n))
if (i <= n) {
parts.push(str.substr(0, i))
return parts.reverse()
@aleclarson
aleclarson / jsperf.md
Last active August 28, 2018 14:02
Performance tests
@aleclarson
aleclarson / README.md
Last active February 11, 2018 22:56
lula - Lua package manager

lula

Try it:

wget https://gist.githubusercontent.com/aleclarson/759b5600974c6a8073eff2e3eb81699f/raw/lula.sh -O ~/bin/lula
chmod +x ~/bin/lula

package.lua

@aleclarson
aleclarson / tarantool-websockets.lua
Created February 15, 2018 13:30 — forked from daurnimator/tarantool-websockets.lua
Tarantool + lua-http websockets nonblocking
#!/usr/bin/env tarantool
local cqueues = require "cqueues"
local fiber = require "fiber"
local socket = require "socket"
package.loaded["http.client"] = nil -- tarantool has a namespace clash
local websocket = require "http.websocket"
local cq = cqueues.new()
-- Hook up cqueues loop inside tarantool fiber
@aleclarson
aleclarson / randomString.js
Last active February 28, 2018 15:37
randomString.js
window.randomString = (function() {
var chars = 'abcdefghijklmnopqrstuvwxyz'
return function randomString(len) {
if (!len) len = 10
var str = ''
for (var i = 0; i < len; i++) {
str += chars[Math.floor(Math.random() * chars.length)]
}
return str
}
@aleclarson
aleclarson / search_lines.moon
Created March 11, 2018 15:40
Search each line for a pattern
-- Search for pattern on each line.
search_lines = (str, pattern) ->
line = str\find '\n'
if line == nil
i = 0
return ->
if i ~= nil
h, i, match = str\find '^'..pattern, i
return h, i, match if h ~= nil
@aleclarson
aleclarson / lua.moon
Created March 16, 2018 22:47
Unfinished Lua sanitizer
:Stack, :in_array, :find_replace, :call = require './utils'
:concat = table
-- 1. Turn unnested `local =` declarations into `env.` mutations
-- 2. Track scoped variables (function params, for..in vars, explicit locals)
-- 3. Ensure all variable refs use `env.` when necessary
-- 4. Rename local vars named "env" or "res" to avoid conflicts
reserved_vars = {'res', 'env'}
scope_keywords = {'do', 'for', 'function', 'repeat', 'then'}
@aleclarson
aleclarson / _parse.coffee
Last active June 19, 2018 00:12
Parsing top-level declarations and external references from .scss modules
{isValue, notValue, assertType} = require 'sass-lexer/utils'
tokenize = require 'sass-lexer'
path = require 'path'
createScope = ->
mixins: []
functions: []
variables: []
pushUnique = (arr, val) ->
@aleclarson
aleclarson / debug.php
Created August 12, 2018 16:56
Simple debug logger
function debug($msg) {
error_log($msg . "\n", 3, getcwd() . '/debug.log');
}