Skip to content

Instantly share code, notes, and snippets.

@vojtatranta
vojtatranta / gist:474949cb54152d6ec61a
Created May 27, 2015 07:04
anything to JSON in python
def jsonize(self, data_dict):
dict_string = {}
for key, value in data_dict.items():
if isinstance(value, QuerySet):
dict_string[key] = serializers.serialize('json', value)
else:
dict_string[key] = json.dumps(value)
json_str = '{'
for key, value in dict_string.items():
json_str += '"%s":%s,' % (key, value)
const passProps = (props, component) => {
return {
type: 'LOCAL_STATE',
props,
component
}
}
const getElementWithLocalState = ({ clicked = false }) => {
#!/bin/bash
#
# Task delete merged local and remote branches
#
EXCLUDE="master|next|release"
# local
git branch --merged remotes/origin/next | grep -v -E "$EXCLUDE" | xargs -n 1 git branch -d
ImageProcessor.prototype.run = function ImageProcessor_run(config) {
return new Promise(function(resolve, reject) {
// If object.size equals 0, stop process
if ( this.s3Object.object.size === 0 ) {
reject("Object size equal zero. Nothing to process.");
return;
}
if ( ! config.get("bucket") ) {
config.set("bucket", this.s3Object.bucket.name);
@vojtatranta
vojtatranta / promise-hell.js
Last active May 3, 2016 22:10
Promise hell
// promise hell
ImageProcessor.prototype.execResizeImage = function ImageProcessor_execResizeImage(option, imageData) {
return new Promise(function(resolve, reject) {
var resizer = new ImageResizer(option.size);
resizer.exec(imageData)
.then(function(resizedImage) {
var reducer = new ImageReducer(option);
reducer.exec(resizedImage)
.then(function(reducedImage) {
// unhell promise
ImageProcessor.prototype.execResizeImage = function ImageProcessor_execResizeImage(option, imageData) {
var resizer = new ImageResizer(option.size);
return resizer.exec(imageData)
.then(function(resizedImage) {
var reducer = new ImageReducer(option);
return reducer.exec(resizedImage)
});
};
@vojtatranta
vojtatranta / electron.html
Created May 10, 2016 11:17
electron angular
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
</body>
<script src="./angular.js"></script>
<?php
function get_local_db()
{
return array(
'username' => 'dbuser',
'hostname' => 'localhost',
'password' => '',
'database' => 'pujcka2'
);
var imageInDOM = document.getElementById('image-' + index);
if (imageInDOM) {
imageInDOM.querySelector('h3').textContent = timeLastUpdated;
} else {
var flickr = document.createElement('div');
var flickrH1 = document.createElement('h1');
var FlickrImage = React.createClass({
render: function() {
// Figure out how long ago this photo was taken.
var fromNow = moment(this.props.image.lastUpdated).fromNow();
// Render away!
return (
<div className="flickr-image">
<h1>{this.props.image.title}</h1>