Skip to content

Instantly share code, notes, and snippets.

View fmcgeough's full-sized avatar

Frank McGeough fmcgeough

View GitHub Profile
@fmcgeough
fmcgeough / findIndex.cpp
Created March 11, 2011 01:43
Binary Searching an Array
#include <iostream>
// find the index of an element in a sorted array
// return index if found, or -1 if not present
int findIndex(int* array, int offset, int sizeOfArray, int value)
{
if (sizeOfArray == 1)
{
if (array[offset] == value)
return offset;
@fmcgeough
fmcgeough / gist:865345
Created March 11, 2011 02:12
regexp_replace
create table test_text_replace(c1 varchar(100));
insert into test_text_replace(c1) values ('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at elit velit, eget auctor urna nullam.');
update test_text_replace set c1 = regexp_replace(c1, 'Lorem', 'Dorem');
select * from test_text_replace;
-- this returns-- Dorem ipsum dolor sit amet, David Levin elit. Nam at elit velit, eget auctor urna nullam.
You can replace text wherever. For example :
Warning: Some directories in /usr/local/share/man aren't writable.
This can happen if you "sudo make install" software that isn't managed
by Homebrew. If a brew tries to add locale information to one of these
directories, then the install will fail during the link step.
You should probably `chown` them:
/usr/local/share/man/de
/usr/local/share/man/de/man1
Warning: libiconv was detected in your PREFIX.
def query_to_csv(sql)
db_result = @db.query(sql)
csv = Array.new(db_result.columns)
db_result.each {|row| csv.push(row.to_a)}
csv
end
sql = 'select * from account_status where account_status_id in ($1)'
params = [1, 2]
# obviously wrong. 2 params instead of 1
db.exec_params(sql, params)
# PG::IndeterminateDatatype: ERROR: could not determine data type of parameter $2
params = [[1,2]]
db.exec_params(sql, params)
# PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: "[1, 2]"
CREATE FUNCTION f_now_immutable_date()
RETURNS date AS
$func$
SELECT CURRENT_DATE;
$func$ LANGUAGE sql IMMUTABLE;
WITH btree_index_atts AS (
SELECT nspname,
indexclass.relname as index_name,
indexclass.reltuples,
indexclass.relpages,
indrelid, indexrelid,
indexclass.relam,
tableclass.relname as tablename,
regexp_split_to_table(indkey::text, ' ')::smallint AS attnum,
indexrelid as index_oid
mix ecto.drop
Compiling 12 files (.ex)
warning: unused alias FishLanded
lib/fishing_spot/models/fish_landed.ex:3
== Compilation error on file lib/fishing_spot/repo.ex ==
** (ArgumentError) missing :adapter configuration in config :fishing_spot, FishingSpot.Repo
lib/ecto/repo/supervisor.ex:37: Ecto.Repo.Supervisor.parse_config/2
lib/fishing_spot/repo.ex:2: (module)
SELECT r.recording_id FROM userdata.recordings r
LEFT OUTER JOIN recording_migrator_recordings_existing rmre ON (rmre.recording_id = r.recording_id)
AND r.account_service_id = 1000
AND rmre.recording_id IS NULL;
recording_id
--------------
1000
10000
(2 rows)
defmodule HdapViewer.AuthTest do
use HdapViewer.ConnCase
alias HdapViewer.Auth
setup %{conn: conn} do
conn =
conn
|> bypass_through(HdaViewer.Router, :browser)
|> get("/")