Wednesday, November 26, 2014

Object.keys()

The Object.keys() method returns an array of a given object's own enumerable properties, in the same order as that provided by a for...in loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).
src

And this is how you iterate the keys of an array:
Object.keys(myArray).forEach(function (key) {
   // do something with obj[key]
});
src

Sunday, November 24, 2013

Flexbox justify-content vs align-items

Csak emlekeztetonek, nehogy megint elrontsam:

main axis: justify-content es ennek megfeleloen -webkit-justify-content
cross axis: align-items es ennek megfeleloen webkit-align-items


Tuesday, November 19, 2013

JQuery .on() event handler hasznalat a click() helyett dinamikusan letrehozott elemeknel

A click() event handler nem fog mukodni dinaikusan letrehozott elemeknel csak ha a letrehozas utan ujra rakotjuk. Az on() event handler-nel meg lehet adni egy selector-t, tehat ha a $(document).ready()-ben irjuk le az on()-t egy ott mar letezo container item-re amibe bekerul majd dinamikusan a valojaban vizsgalando item akkor minden renben lesz.


<html>
    <button id="add">Add new</button>
    <div id="container">
        <button class="alert">alert!</button>
    </div>
</html>

$("div#container").on('click', 'button.alert', function() {
    alert(1);
});


Sunday, October 13, 2013

Friday, April 05, 2013

DigitalColor Meter

Ha mac os-en kell egy keppont szinet megallapitani, akkor DigitalColor Meter.

Wednesday, April 03, 2013

sips

Ha mac os-en egy keppel kell aprobb dolgokat csinalni arra jo a sips. Peldaul ha van egy png file-unk amirol a sips -g all picture.png megmondja, hogy a typeIdentifier valojaban public.jpeg es png-t akarunk csinalni belole, akkor egyszeruen:
sips -s format png picture.png --out newpicture.png

Friday, March 08, 2013

SQL datetime & UTC

A datetime nem tárol DateTimeKind-ot ezert jobb megoldás lehet a datetimeoffset, de ha ez nem megoldható viszont tudjuk a Kind-ot (itt UTC) akkor miután kiolvastuk a DateTime-ot az SQLDataReader-rel annak kétféleképpen is megadhatjuk a típusát:
  • DateTime unspecified = reader.GetDateTime(index);
    DateTime d = new DateTime(unspecified.Ticks, DateTimeKind.UTC);
  • DateTime unspecified = reader.GetDateTime(index);
    DateTime d2= DateTime.SpecifyKind(unspecified, DateTimeKind.UTC);
Persze jobb ezt egy extensionbe tenni:
public static class SqlDataReaderExtensions {
    public static DateTime GetDateTimeUtc(this SqlDataReader reader, int columnOrdinal) {
        DateTime dt = new DateTime(reader.GetDateTime(0).Ticks, DateTimeKind.Utc);
        return dt;
    }
}
és utána ezt használni:
DateTime d = reader.GetDateTimeUTC(index);

Monday, July 16, 2012

ASP.NET Routing

Itt van a hivatalos leiras amibol kihagytak a parameter passzolast, de arra is van megoldas.

Friday, May 18, 2012

Show Current File in Project View

Visual Studio > Ctrl + Alt + L (Show in Solution Explorer)
Eclipse > Alt + Shift + w (Show in)
IntelliJ IDEA > Alt + F1 (Select current file or symbol in any view)

innen

Monday, April 16, 2012

Web Browser Control rendering mode

Mivel default-bol nem a legfrissebb IE szerint renderel a windowsos web browser control, ezert ha azt szeretnenk, hogy adott oldalt megis ugy renderelje akkor ezt kell megadni:

Monday, March 12, 2012

[Android]__FUNCTION__ java-ban logolashoz

Innen es innen meritve egy sajat loggolo class-ban lehet valami ilyesmi:


public static void LogD(String tag, String msg) {
StackTraceElement ste = new Throwable().getStackTrace()[1];
String s = "[" + ste.getClassName() + "." + ste.getMethodName() + "(" + ste.getLineNumber() + ")] " ;
Log.d(tag, s + msg);
}

Thursday, December 15, 2011

Nem latta az Eclipse a Nexus S-t


Csak emlekeztetonek:

Hiaba ment fel USB Driver-bol a 4-es meg igy sem latta az Eclipse a Nexus S-t, mert efelejtettem vegigcsinalni a Driver installalast. Pedig itt le van irva rendesen.

Thursday, October 27, 2011

urllib2 POST progress

Innen.

It is possible but you need to do a few things:

  • Fake out the urllib2 subsystem into passing a file handle down to httplib by attaching a __len__attribute which makes len(data) return the correct size, used to populate the Content-Length header.
  • Override the read() method on your file handle: as httplib calls read() your callback will be invoked, letting you calculate the percentage and update your progress bar.

This could work with any file-like object, but I've wrapped file to show how it could work with a really large file streamed from disk:

import os, urllib2
from cStringIO import StringIO

class Progress(object):
def __init__(self):
self._seen = 0.0

def update(self, total, size, name):
self._seen += size
pct
= (self._seen / total) * 100.0
print '%s progress: %.2f' % (name, pct)

class file_with_callback(file):
def __init__(self, path, mode, callback, *args):
file
.__init__(self, path, mode)
self.seek(0, os.SEEK_END)
self._total = self.tell()
self.seek(0)
self._callback = callback
self._args = args

def __len__(self):
return self._total

def read(self, size):
data
= file.read(self, size)
self._callback(self._total, len(data), *self._args)
return data

path
= 'large_file.txt'
progress
= Progress()
stream
= file_with_callback(path, 'rb', progress.update, path)
req
= urllib2.Request(url, stream)
res
= urllib2.urlopen(req)

Output:

large_file.txt progress: 0.68
large_file
.txt progress: 1.36
large_file
.txt progress: 2.04
large_file
.txt progress: 2.72
large_file
.txt progress: 3.40
...
large_file
.txt progress: 99.20
large_file
.txt progress: 99.87
large_file
.txt progress: 100.00