Skip to content

Instantly share code, notes, and snippets.

View scvalex's full-sized avatar

Alexandru Scvorțov scvalex

View GitHub Profile
@scvalex
scvalex / pull_contacts.py
Created July 15, 2010 23:25
Pull data from Google Contacts
#!/usr/bin/python
"""Module for pulling contacts out of Google and storing them to disk
(or something).
See the official guide for a more in-depth look at GData Python
http://code.google.com/apis/contacts/docs/1.0/developers_guide_python.html
"""
import atom
@scvalex
scvalex / xmonad.hs
Created February 10, 2011 16:27
My xmonad.hs
import XMonad
import qualified XMonad.StackSet as W
import qualified Data.Map as M
import Data.List (isPrefixOf, (\\), tails)
import Data.Maybe (isNothing, fromMaybe, isJust, catMaybes)
import System.IO
import System.Posix.Unistd
import System.Posix.Files
@scvalex
scvalex / TxDontLoseMessages.java
Created October 6, 2010 10:43
Don't lose messages with RabbitMQ Transactions
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
@scvalex
scvalex / quine.sh
Last active November 30, 2019 16:08
A real quine in Bash
#!/bin/bash
T='#!/bin/bash
Q=$(printf "\x27") # A literal single quote
echo "$T" | head -n2 -
echo T=$Q"$T"$Q
echo "$T" | tail -n6 -'
@scvalex
scvalex / ConfirmDontLoseMessages.java
Created October 6, 2010 10:47
Don't lose messages with RabbitMQ Publisher Acknowledgements
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
@scvalex
scvalex / Warshall.hs
Created May 4, 2010 21:00
Floyd-Warshall in 2 lines of Haskell
module Warshall where
import Data.Char ( isAlpha )
import Data.List ( nub, sort )
import System.Environment ( getArgs )
import Text.Parsec
import Text.Parsec.String
import Text.Printf ( printf )
type Vertex a = a
@scvalex
scvalex / phil.c
Created December 18, 2012 14:22
Starving philosophers
#include <pthread.h>
#include <stdio.h>
void philosopher1(pthread_mutex_t chopsticks[]) {
pthread_mutex_lock(&chopsticks[0]);
pthread_mutex_lock(&chopsticks[1]);
printf("Philosopher 1 is full.\n");
pthread_mutex_unlock(&chopsticks[0]);
pthread_mutex_unlock(&chopsticks[1]);
}
@scvalex
scvalex / counter.html
Last active December 3, 2017 10:47
counter
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Counter</title>
<link rel="stylesheet" href="/r/screen.css" media="screen">
<meta name="description" content="An HTML5 counter">
@scvalex
scvalex / cnc.c
Created April 8, 2011 19:01
Mastermind solver in C
#include <stdio.h>
#include <string.h>
int rulled_out[10000 / sizeof(int) + 1];
int num_left;
// Try guess GUESS and mark the entries in RULLED_OUT that match the
// numbers that cannot be the secret (i.e. numbers that compared to
// GUESS are not COMP).
void update_rulled_out(int guess, int comp);
@scvalex
scvalex / README
Created April 30, 2011 02:27
Simple Python script to upload a file to Rackspace CloudFiles
CONFIGURATION
-------------
To setup, simply set your username and API access key in the
cloudfiles.get_conenction call. If you're not using the UK
version of Rackspace, remove the third parameter from the above
call.
EXAMPLE USAGE
-------------