Skip to content

Instantly share code, notes, and snippets.

@JosephPecoraro
JosephPecoraro / shell-execution.rb
Last active September 10, 2023 10:12
Shell Execution in Ruby
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Synchronous (blocking)
# Returns the output of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
@endolith
endolith / peakdet.m
Last active February 14, 2024 21:27
Peak detection in Python [Eli Billauer]
function [maxtab, mintab]=peakdet(v, delta, x)
%PEAKDET Detect peaks in a vector
% [MAXTAB, MINTAB] = PEAKDET(V, DELTA) finds the local
% maxima and minima ("peaks") in the vector V.
% MAXTAB and MINTAB consists of two columns. Column 1
% contains indices in V, and column 2 the found values.
%
% With [MAXTAB, MINTAB] = PEAKDET(V, DELTA, X) the indices
% in MAXTAB and MINTAB are replaced with the corresponding
% X-values.
@jboner
jboner / latency.txt
Last active June 17, 2024 02:27
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@kgrz
kgrz / mongoid3_sinatra_config.rb
Created August 22, 2012 17:04
A Better Mongoid Sinatra configuration implementation. Using settings hash for db options sucks!
# This is a modification of the blogpost on how to use Mongoid and Sinatra.
# Here is the original blogpost http://www.garrensmith.com/2010/09/11/Mongoid-sinatra.html
# The modification lets you use Mongoid 3.0 with the new Moped driver
# The new Moped driver uses the Sessions component to define the MongoDB connection rather
# than the Mongo::Connection.new that is used in the case of the default Ruby driver.
# Moped::Session.new vs Mongo::Connection.new
# Mongoid.load!(yaml_config.yml) is used to build the config hash. Alternatively, the hash can
# be built manually by using Mongoid.config {|config| ...} syntax. The config.sessions hash
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active June 17, 2024 10:28
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@beezly
beezly / gist:4250079
Created December 10, 2012 11:24
Google Script Spreadsheet function to iterate over all cells and insert the value 0 if the cell is blank
function zeroCells() {
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheet=ss.getSheets()[0];
var selection=sheet.getDataRange();
var columns=selection.getNumColumns();
var rows=selection.getNumRows();
for (var column=1; column < columns; column++) {
for (var row=1; row < rows; row++) {
var cell=selection.getCell(row,column);
if (cell.isBlank()) {
   ∧,_,∧
  (`・ω・´)  n__
`__n 〉  ⌒\/ 、_∃
E_,У ∧  \_/
  \_/ \  丶
     / y  ノ
    / / /
   ( ( 〈
    \ \ \
    (_(__)
@soimort
soimort / gist:4553984
Created January 17, 2013 05:46
lamma
Δ~~Δ
ξ •ェ• ξ
ξ ~ ξ
ξ  ξ
ξ  ⌒~~~~〇
ξ   ,     ξ
ξ ξξ ξ~~~ξ ξ
ξ_ξ ξ_ξ   ξ_ξ
@gbaptista
gbaptista / tips.sh
Last active December 12, 2015 01:58
Bash tips.
# RVM sudo.
rvmsudo passenger-install-nginx-module
rvmsudo ruby test.rb
# Root console.
sudo clear; sudo gnome-terminal 2>/dev/null &
# Find service:
ps aux | grep 'nginx'
┏┳━━━━━━┳┓
┃┃・ ▼ ・┃┃
┃┃〃┗┻┛〃┃┃
┗┫┏┓ ┏┓ ┣┛
┗┫ ┣━┫┣━┛