Skip to content

Instantly share code, notes, and snippets.

View OndrejSlamecka's full-sized avatar

Ondřej Slámečka OndrejSlamecka

View GitHub Profile
@OndrejSlamecka
OndrejSlamecka / contains.cpp
Created July 12, 2014 10:26
C++ contains (not tested)
template <template <class> class C, typename T>
bool contains(C<T> container, T item) {
return std::find(container.begin(), container.end(), item) != container.end();
}
@OndrejSlamecka
OndrejSlamecka / yt.js
Last active August 29, 2015 14:07
YellowText fork working with browserify and taking style definition from #yt-default-style (or id specified in textarea's data-styleelementid)
var jQuery = require('jquery');
/*
* Yellow Text - v0.5.0
* Yellow Text is a beautiful text editor which makes creating content fun again. It ships with a beautiful theme and really clever shortkeys.
* https://github.com/stefanvermaas/yellow-text
*
* Made by Stefan Vermaas
* Under BEERWARE License
*/
@OndrejSlamecka
OndrejSlamecka / TexyCache.php
Created January 3, 2012 18:37
Class for caching Texy! results
<?php
/**
* TexyCache - class for caching Texy! results
* -------------------------------------------
*
* Using Texy! the great web text markup-language processor by David Grudl (http://davidgrudl.com)
* For more information please visit http://texy.info
*
* @author Ondrej Slamecka, 2010
* @license New BSD license (see http://texy.info/en/licence)
/* Ondrej Slamecka 2012
* <img id=loader><tr><a class='ajax highlight parent-tr'>Edit</a></tr>
* When you click the link, it will show the loader, on success it will hide the loader and animate <tr> (because of parent-tr)
* Color animation requires https://github.com/jquery/jquery-color
*/
function processSnippets(snippets)
{
if (snippets)
@OndrejSlamecka
OndrejSlamecka / gist:2256836
Created March 30, 2012 22:44
Get style property of DOM element using JavaScript
/**
* Returns styleProperty of given element
*/
function getStyle(el, styleProperty)
{
if (el.currentStyle)
return el.currentStyle[styleProperty];
else if (window.getComputedStyle)
return document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProperty);
}
@OndrejSlamecka
OndrejSlamecka / gist:2287537
Created April 2, 2012 22:03
Google Maps v3 API useGeolocation
/* Ondrej Slamecka 2012 */
/**
* @param success Callback called on success
* @returns bool
*/
google.maps.Map.prototype.useGeolocation = function(success, failure)
{
if(typeof success === 'undefined')
return false;
@OndrejSlamecka
OndrejSlamecka / DomClass.coffee
Created August 16, 2012 15:49
Manipulate DOM class with CoffeeScript
# DOM Class - based on http://www.openjs.com/scripts/dom/class_manipulation.php
class @DomClass
this.has = (el, className) ->
return el.className.indexOf(className) != -1
this.add = (el, className) ->
if !this.has(el, className)
el.className += ' ' + className
@OndrejSlamecka
OndrejSlamecka / ascii85.c
Last active December 15, 2015 01:09
This was just a homework so it needs few improvements for real use.
// ascii85 encoder/decoder prototype
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int ascii85encode(unsigned char *input, char *output)
{
size_t inputSize = strlen((char *)input), inputIndex = 0;
unsigned int i = 0, j = 0, chunk = 0;
@OndrejSlamecka
OndrejSlamecka / lineq.c
Last active December 15, 2015 13:08
Solves system of linear equations in field Z_p, where p is prime. In case of many solutions finds the lexicografically smallest solution (smallest x1, x2…). With -e parameter prints number of solutions up to 10^12. A complete solution to http://cecko.eu/public/lineq_2013 [cs]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* --- IO --- */
/**
* @brief Reads line of text, reallocates memory if needed
* @param input
* @param size
@OndrejSlamecka
OndrejSlamecka / Mailer.php
Last active December 21, 2015 23:49
Sending simple emails should be easier in Nette Framework.
<?php
namespace App;
class Mailer
{
/** @var \Nette\Mail\IMailer @inject */
public $mailer;