Skip to content

Instantly share code, notes, and snippets.

View kitek's full-sized avatar
🏠
Working from home

Marcin Kitowicz kitek

🏠
Working from home
View GitHub Profile
@kitek
kitek / redrawPage.js
Created July 19, 2013 07:05
Funkcja wykorzystywana do force re-renderingu ([email protected] z pustymi stronami)
// Funkcja wykorzystywana do force re-renderingu ([email protected] z pustymi stronami)
function redrawPage(top) {
document.body.scrollTop = 1;
document.body.scrollTop = 0;
$(function() {
document.body.scrollTop = top + 1;
document.body.scrollTop = top;
});
}
@kitek
kitek / 9patchReplace.java
Created June 21, 2013 14:01
Replace 9patch background with padding
NinePatchDrawable bg = (NinePatchDrawable) getResources().getDrawable(R.drawable.button_new_light);
int pL = btnLike.getPaddingLeft();
int pR = btnLike.getPaddingRight();
int pT = btnLike.getPaddingTop();
int pB = btnLike.getPaddingBottom();
if(Build.VERSION.SDK_INT >= 16) {
btnLike.setBackground(bg);
} else {
btnLike.setBackgroundDrawable(bg);
@kitek
kitek / bitmap.java
Created June 21, 2013 09:24
How to convert a Drawable to a Bitmap?
Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
R.drawable.icon_resource);
@kitek
kitek / compare.txt
Last active January 3, 2016 14:59
Porównanie string vs bool
Porównanie string vs bool:
"00" == "0" → bool(true)
"0" == false → bool(true)
ale już:
"00" == false → bool(false)
Porównanie null vs bool vs string:
null == false → bool(true)
@kitek
kitek / compare.txt
Last active January 3, 2016 15:00
Porównanie int vs string
0 == "Lorem ipsum" → bool(true)
15 == "15 kwiatów w wazonie" → bool(true)
@kitek
kitek / compare.txt
Last active January 3, 2016 15:29
Porównanie liczb zapisanych w string'ach.
"1.00000000000000001" == "0.1e1" → bool(true)
"+1" == "0.1e1" → bool(true)
"1e0" == "0.1e1" → bool(true)
"-0e10" == "0" → bool(true)
"1000" == "0x3e8" → bool(true)
"1234" == " \t\r\n 1234" → bool(true)
ZEND_API int zend_binary_strcmp(const char *s1, uint len1, const char *s2, uint len2) /* {{{ */
{
int retval;
if (s1 == s2) {
return 0;
}
retval = memcmp(s1, s2, MIN(len1, len2));
if (!retval) {
return (len1 - len2);
ZEND_FUNCTION(strcmp)
{
char *s1, *s2;
int s1_len, s2_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &s1, &s1_len, &s2, &s2_len) == FAILURE) {
return;
}
RETURN_LONG(zend_binary_strcmp(s1, s1_len, s2, s2_len));
@kitek
kitek / strlen.c
Last active December 18, 2015 00:09
ZEND_FUNCTION(strlen)
{
char *s1;
int s1_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &s1, &s1_len) == FAILURE) {
return;
}
RETVAL_LONG(s1_len);
@kitek
kitek / blad.php
Last active January 3, 2016 15:30
Wyliczanie błędów względnych i bezwzględny dla uBenchmarka.
<?php
// Dane wejściowe (wklej tutaj kolejne)
$dane = "0.23110198974609
0.23308801651001
0.23321080207825
0.23291993141174";
// Koszt petli + liczba iteracji