Skip to content

Instantly share code, notes, and snippets.

View georgebyte's full-sized avatar

George Byte georgebyte

View GitHub Profile
@georgebyte
georgebyte / mnist.py
Last active July 31, 2019 13:46
Python: Mnist Reader
def get_data_and_labels(images_filename, labels_filename):
print("Opening files ...")
images_file = open(images_filename, "rb")
labels_file = open(labels_filename, "rb")
try:
print("Reading files ...")
images_file.read(4)
num_of_items = int.from_bytes(images_file.read(4), byteorder="big")
num_of_rows = int.from_bytes(images_file.read(4), byteorder="big")
@georgebyte
georgebyte / sublime-shortcuts.txt
Last active March 6, 2017 06:41
Document: Sublime Text 2 Shortcuts and Packages
Packages:
"Package Control"
"Gist"
"Clipboard History"
"Emmet"
"AdvancedNewFile"
"Nettuts+ Fetch"
"Goto Documentation"
"Prefixr"
"SublimeLinter"
@georgebyte
georgebyte / background-color-picker.js
Last active September 13, 2020 20:13
jQuery: Background color picker (pick color from image by clicking on it)
var image = new Image();
image.src = "sample.jpg";
$(image).load(function() {
ctx.drawImage(image, 0, 0);
});
$(canvas).click(function(e) {
var canvasOffset = $(canvas).offset();
var canvasX = Math.floor(e.pageX-canvasOffset.left);
var canvasY = Math.floor(e.pageY-canvasOffset.top);
@georgebyte
georgebyte / Rdate.java
Created March 17, 2013 17:14
Java: Rdate (tool for querying the current time from a network server)
import java.io.InputStream;
import java.net.Socket;
import java.util.Date;
public class Rdate {
public static void main(String[] args) {
try {
Socket s = new Socket("ntp1.arnes.si", 37);
InputStream input = s.getInputStream();
@georgebyte
georgebyte / get-env-variable.py
Last active March 6, 2017 06:40
Django: Environment variable in Django settings
# Load environment variable into Django settings.
# Usage: SOME_SECRET_KEY = get_env_variable("SOME_SECRET_KEY")
import os
from django.core.exceptions import ImproperlyConfigured
def get_env_variable(var_name):
""" Get the environment variable or return exception """
try:
return os.environ[var_name]
@georgebyte
georgebyte / gmail.py
Created April 23, 2013 14:56
Python: Gmail Parser
import imaplib
import StringIO
import rfc822
obj = imaplib.IMAP4_SSL("imap.gmail.com", "993")
obj.login("xxx@gmail.com", "pass")
print obj.list()
obj.select("[Gmail]/Vsa po&AWE-ta")
m = obj.search(None, "ALL")[1][0]
alli = m.split()
@georgebyte
georgebyte / show-more-animated.html
Last active March 6, 2017 06:40
jQuery: Resize a div to show the whole text inside. (Show more/ show less animated toggle)
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function()
{
$("#toggle_link").click(function(event){
event.preventDefault();
var heightExpanded = $("#box").get(0).scrollHeight - 2 * parseInt($("#box").css('padding'));
@georgebyte
georgebyte / json-data-attribute.txt
Last active October 5, 2023 10:28
HTML5, jQuery: JSON in data attribute
HTML:
<a href="#" data-lang-string='{"show":"{{ Lang::get('header.show_menu') }}", "hide":"{{ Lang::get('header.hide_menu') }}"}' id="toggle_navigation">{{ Lang::get('header.show_menu') }}</a>
JAVASCRIPT:
$("#toggle_navigation").data('lang-string').show;
@georgebyte
georgebyte / node-express-create-project-readme.md
Last active March 6, 2017 06:39
Node, Express, Hogan, Compass: Create Node app with Express web aplication framework + Hogan and Compass

Create node.js app with Express web aplication framework + Hogan and Compass

Install express and nodemon.

sudo npm install -g express
sudo npm install -g nodemon

Create express project.

@georgebyte
georgebyte / css-properties-order.css
Last active March 6, 2017 06:39
CSS: CSS properties order
.selector {
/* Positioning */
position: absolute;
z-index: 10;
top: 0;
right: 0;
/* Display & Box Model */
display: inline-block;
overflow: hidden;