Skip to content

Instantly share code, notes, and snippets.

View alexanderk23's full-sized avatar

Alexander Kovalenko alexanderk23

View GitHub Profile
@alexanderk23
alexanderk23 / Makefile
Last active December 31, 2015 04:09
Makefile
UNAME := $(shell uname -s)
ifeq ($(UNAME),Darwin)
OSFLAGS=-D_OSX
endif
ifeq ($(UNAME),Linux)
OSFLAGS=-D_LINUX
endif
CC=gcc
CFLAGS=-std=gnu99 -lm -s -x c -O2 -Wall -Wno-unused -fno-optimize-sibling-calls -fno-strict-aliasing -DONLINE_JUDGE $(OSFLAGS)
SOURCES=my_strategy.c runner.c remote_process_client.c model/world.c platform/net.c
@alexanderk23
alexanderk23 / deep_open_struct.rb
Created December 4, 2013 12:56
DeepOpenStruct with recursive to_h
class DeepOpenStruct < OpenStruct
def to_h
convert_to_hash_recursive self.dup
end
def self.load item
raise ArgumentError, "DeepOpenStruct must be passed a Hash or Array" unless(item.is_a?(Hash) || item.is_a?(Array))
self.convert_from_hash_recursive item
end
@alexanderk23
alexanderk23 / tree.md
Created November 10, 2013 19:20 — forked from hrldcpr/tree.md

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

namespace :symfony do
namespace :assets do
desc "Updates assets version"
task :update_version do
run "sed -i 's/\\(assets_version: \\)\\(.*\\)$/\\1 #{real_revision}/g' #{latest_release}/app/config/config.yml"
end
end
end
before "symfony:assetic:dump" do
"""Generic linux daemon base class for python 3.x.
Source: http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/"""
import sys, os, time, atexit, signal, errno
class daemon:
"""A generic daemon class.
Usage: subclass the daemon class and override the run() method."""
@alexanderk23
alexanderk23 / gist:5209578
Last active December 15, 2015 05:29
Pure JS solution
<html>
<head>
<script src="https://raw.github.com/remy/twitterlib/master/twitterlib.min.js"></script>
<script src="https://raw.github.com/timrwood/moment/2.0.0/min/moment.min.js"></script>
</head>
<body>
<div id="tweet" data-username="bountify"></div>
<script>
var tweet = document.getElementById('tweet');
var username = tweet.getAttribute('data-username');