Skip to content

Instantly share code, notes, and snippets.

View superhawk610's full-sized avatar
🌠
drifting on a solar wind

Aaron Ross superhawk610

🌠
drifting on a solar wind
View GitHub Profile
@jonleighton
jonleighton / base64ArrayBuffer.js
Last active April 1, 2025 05:52
Encode an ArrayBuffer as a base64 string
// Converts an ArrayBuffer directly to base64, without any intermediate 'convert to string then
// use window.btoa' step. According to my tests, this appears to be a faster approach:
// http://jsperf.com/encoding-xhr-image-data/5
/*
MIT LICENSE
Copyright 2011 Jon Leighton
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@ericchaves
ericchaves / weird.js
Created April 30, 2012 17:21
instanceof regexp evalutes to false inside a sandbox
var reg = /^[a-z]$/;
console.log('case 01: typeof /^[a-z]$/ returns %s', typeof reg);
console.log('case 02: /^[a-z]$/ instanceof RegExp returns %s', reg instanceof RegExp);
console.log('case 03: /^[a-z]$/.constructor.name === "RegExp" returns %s', reg.constructor.name === 'RegExp');
var util = require('util'),
vm = require('vm'),
sandbox = { u: reg };
@mshafrir
mshafrir / states_hash.json
Created May 9, 2012 17:05
US states in JSON form
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active May 31, 2025 19:19
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@iwanbk
iwanbk / split_string_by_line.lua
Created April 29, 2013 03:39
Split string by line in Lua
for line in yourString:gmatch("([^\n]*)\n?") do
-- do something
end
@todgru
todgru / aws-ec2-redis-cli.md
Created June 12, 2014 23:01
AWS redis-cli on EC2
@glen-cheney
glen-cheney / encoding-video.md
Last active November 24, 2024 10:09
Encoding video for the web

Encoding Video

Installing

Install FFmpeg with homebrew. You'll need to install it with a couple flags for webm and the AAC audio codec.

brew install ffmpeg --with-libvpx --with-libvorbis --with-fdk-aac --with-opus
@henriquemenezes
henriquemenezes / postgresql-set-id-seq.sql
Created March 31, 2016 12:23
PostgreSQL set Next ID Sequence Value to MAX(id) from Table
-- Get Max ID from table
SELECT MAX(id) FROM table;
-- Get Next ID from table
SELECT nextval('table_id_seq');
-- Set Next ID Value to MAX ID
SELECT setval('table_id_seq', (SELECT MAX(id) FROM table));
@zenorocha
zenorocha / etc-hosts-on-win.md
Last active May 19, 2025 05:25
/etc/hosts on Windows

1. Get your IP Address

echo `ifconfig $(netstat -nr | grep -e default -e "^0\.0\.0\.0" | head -1 | awk '{print $NF}') | grep -e "inet " | sed -e 's/.*inet //' -e 's/ .*//' -e 's/.*\://'`

2. Modify your hosts file

notepad

@thebugcatcher
thebugcatcher / n_primes.ex
Last active February 1, 2021 09:48
Find if a number is prime in elixir and get a list of primes.
# Given an input, this program returns a list of all primes numbers less than the input.
defmodule NPrimes do
def get_primes(n) when n < 2, do: []
def get_primes(n), do: Enum.filter(2..n, &is_prime?(&1))
defp is_prime?(n) when n in [2, 3], do: true
defp is_prime?(x) do
start_lim = div(x, 2)
Enum.reduce(2..start_lim, {true, start_lim}, fn(fac, {is_prime, upper_limit}) ->