Skip to content

Instantly share code, notes, and snippets.

View al3xandru's full-sized avatar

Alex Popescu al3xandru

View GitHub Profile
// Check out the where clause of the Generic
// Also the `_`
func anyCommonElements <T, U where T: SequenceType, U: SequenceType, T.Generator.Element: Equatable, T.Generator.Element == U.Generator.Element> (lhs: T, _ rhs: U) -> Bool {
}
// should the function be invoked or is this an error
anyCommonElements(["a", "b", "c"], [1])
# Single-line version:
(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)/)(?:[^\s()<>{}\[\]]+|\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\))+(?:\([^\s()
# sample output for 5742
# feel free to give more sensible / interesting names to KSs and CFs ordering is based on time of creation of the KS/CF.
lyubent:bin lyubentodorov$ ./nodetool listsnapshots
Snapshot Details:
Snapshot name Keyspace name Column family name True size Size on disk
1393952912539 europe resources 3.44 MB 3.46 MB
1393952912539 europe countries 0 bytes 16.86 MB
1393952912539 asia countries 0 bytes 16.41 MB
1393952912539 northamerica countries 0 bytes 16.17 MB
@al3xandru
al3xandru / CqlLexer.py
Last active August 29, 2015 13:57
A Pygments lexer for Cassandra Query Language (CQL)
class CqlLexer(RegexLexer):
"""
Lexer for Cassandra Query Language.
Spec available `here<https://cassandra.apache.org/doc/cql3/CQL.html>`_.
"""
name = 'CQL'
aliases = ['cql']
filenames = ['*.cql']
mimetypes = ['text/x-sql']
@al3xandru
al3xandru / MyClient.java
Created March 26, 2014 03:52
A very basic example of connecting to a Cassandra node using DataStax Java Driver
package com.example.cstar;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
public class MyClient {
public MyClient() {
}
@al3xandru
al3xandru / gist:76d1239bac9bf4fe4729
Created May 24, 2014 19:04
Twitter shorten links
al3xandru $ curl -I -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.76.4 (KHTML, like Gecko) Version/7.0.4 Safari/537.76.4" http://t.co/QgPZfAwK0z
HTTP/1.1 200 OK
cache-control: private,max-age=300
content-length: 0
content-type: text/html; charset=utf-8
date: Sat, 24 May 2014 19:00:20 GMT
expires: Sat, 24 May 2014 19:05:20 GMT
server: tfe
set-cookie: muc=acc5d3c2-431f-4f4d-84ba-7e48d3c7edbd;Domain=t.co;Expires=Thu, 05-May-2016 19:00:20 GMT
x-xss-protection: 1; mode=block
@al3xandru
al3xandru / gist:272e0de1d399f6bae3d3
Created June 11, 2014 04:57
Example connectionList.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<connectionList>
<connections>
<name>Cassandra 2.0.7</name>
<hosts>NODE IP</hosts>
<port>9042</port>
<compression>NONE</compression>
<requiresCredentials>false</requiresCredentials>
<ssl>false</ssl>
<storePassword>false</storePassword>
@al3xandru
al3xandru / preprocessor_fun.h
Last active September 13, 2015 06:52 — forked from aras-p/preprocessor_fun.h
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
@al3xandru
al3xandru / gist:1032222
Created June 17, 2011 20:18
Getting started with VMware CloudFoundry, MongoDB and Node.js
var record_visit = function(req, res){
/* Connect to the DB and auth */
require('mongodb').connect(mongourl, function(err, conn){
conn.collection('ips', function(err, coll){
/* Simple object to insert: ip address and date */
object_to_insert = { 'ip': req.connection.remoteAddress, 'ts': new Date() };
/* Insert the object then print in response */
/* Note the _id has been created */
coll.insert( object_to_insert, {safe:true}, function(err){
@al3xandru
al3xandru / gist:1156476
Created August 19, 2011 09:48
Open iTerm in Current Folder
on run {input, parameters}
tell application "Finder"
set sel to selection
if (count sel) > 0 then
set myTarget to item 1 of sel
else if (count window) > 0 then
set myTarget to target of window 1
else
set myTarget to path to home folder
end if