Skip to content

Instantly share code, notes, and snippets.

View arossouw's full-sized avatar

Arno Rossouw arossouw

  • Anonymous
View GitHub Profile
(require '[clojure.java.io :as io])
(use '[clojure.string :only (join)])
;; logfile contains:
;; login: [10.0.3.162] user1@domain.co.za plaintext User logged in
(def re-email #"\s+\'([a-z\.\-0-9]+?\@[a-z\.\_\-0-9]+)\'$")
(def re-imap-login #"login\:\s\[[0-9\.]+\]\s([a-z\.\-0-9]+?\@[a-z\.\_\-0-9]+)")
(defn lines-re [file]
(keep #(last (re-find re-imap-login %)) (line-seq (io/reader file))))
@arossouw
arossouw / gist:fb4bc179c5a56302a36b
Created March 12, 2015 07:59
Rust - Beginnings (MySQL Client)
extern crate mysql;
extern crate time;
use time::Timespec;
use std::num::Float;
use mysql::conn::{MyOpts};
use mysql::conn::pool::{MyPool};
use mysql::value::{from_value};
use std::default::{Default};
use std::f32;
@arossouw
arossouw / mysql_sysbench_1000.sh
Last active August 29, 2015 14:18
8 Threads sysbench 1000 rows - mysql
#!/bin/bash
ROWS=10000
touch result.dat
for ENGINE in "myisam" "innodb"
do
CSV=$ENGINE-$ROWS.csv
cp /dev/null $CSV
for threads in 2 4 6 8
do
@arossouw
arossouw / mysql-schema-diff.clj
Created April 1, 2015 11:36
mysql-schema-diff
(require '[clojure.java.jdbc :as jdbc])
(require '[clojure.set :as set])
(use 'clojure.data)
(def not-nil? (complement nil?))
(def sql-query ["SELECT concat(table_schema,'.',table_name) as 'schema',table_rows FROM tables
where table_schema <> 'mysql'
and table_schema <> 'information_schema'
and table_name NOT REGEXP '[0-9]'
and table_rows > 0"])
#include <iostream>
#include <vector>
#include <string>
#include <map>
class exam {
int exam_questions;
int exam_passscore;
std::string exam_number;
std::string subject;
@arossouw
arossouw / query-attempt-mysql.rs
Created April 23, 2015 08:29
Newbie simple select query - mysql-simple
extern crate mysql;
extern crate time;
use mysql::conn::{MyOpts};
use mysql::value::Value;
use mysql::conn::pool::{MyPool};
use mysql::value::{from_value};
use std::default::{Default};
use std::vec::Vec;
;; User behaviors
;; -----------------------------
;; Behaviors are stored as a set of diffs that are merged together
;; to create the final set of functionality that makes up Light Table. You can
;; modify these diffs to either add or subtract functionality.
;;
;; Behaviors are added to tags, objects with those tags then automatically gain
;; whatever logic the behavior imparts. To see a list of user-level behaviors,
;; start typing a word related to the functionality you want in between the square
;; brackets (e.g. "theme").
@arossouw
arossouw / country_code_europe.sql
Created October 15, 2015 04:15
postgresql semi-join
select *
from country
where country.code in
(select code
from country
where population > 7*1000*1000)
and country.continent = 'Europe';
QUERY PLAN
------------------------------------------------------------------------
@arossouw
arossouw / PostgresIndex01.txt
Created October 16, 2015 13:03
Postgres Index example 01
Before:
EXPLAIN SELECT
e.entry_category,
tp.transaction_type,
t.transaction_description,
t.transaction_date,
te.amount
FROM transaction t
inner join transaction_type tp on
def is_anagram(word, anagram):
return len(list(word)) == len([char for char in list(word) if char in list(anagram)])
>>> s = "Orchestra"
>>> b = "Carthorse"
>>> [char for char in list(s) if char.lower() in b.lower()]
['O', 'r', 'c', 'h', 'e', 's', 't', 'r', 'a']
>>> b = ['Carthorse']
>>> [char for char in list(s) if char.lower() in "".join(b).lower()]