Skip to content

Instantly share code, notes, and snippets.

View diewland's full-sized avatar
✳️

diewland.eth diewland

✳️
View GitHub Profile
@diewland
diewland / ez_db.php
Last active July 8, 2017 08:51
$pdo helper class
<?php // require initialize $pdo from outside
class EzDb {
// init pdo function
public static function init_pdo($host, $db_name, $user, $pass){
global $pdo;
return new PDO(
"mysql:host=$host;dbname=$db_name;charset=utf8",
$user,
$pass,
@diewland
diewland / download_flickr_photos.py
Created November 16, 2016 10:57
Download flickr 100 photos from api
import requests
import urllib
tag = 'person'
url = "https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=881cbcfeb398828ea12b253c1743224e&text=%s&format=json&nojsoncallback=1" % tag
proxies = {'http': 'http://your.proxy:port/'}
r = requests.get(url)
image = urllib.URLopener(proxies)
@diewland
diewland / bulma-combobox-css-fixed.css
Last active February 20, 2017 09:08
Fixed some elements css of bulma.io
/*
--- combobox with icon ---
<div class="control has-icon">
<div class="select is-fullwidth">
<select name='my_cbb'>
<option value='1'>value 1</option>
<option value='2'>value 2</option>
<option value='3'>value 3</option>
</select>
</div>
@diewland
diewland / debug_post.php
Last active December 22, 2016 01:14
Display beautiful variable data to screen
function debug_post(){
echo '<pre>'.print_r($_POST, true).'</pre>';
}
@diewland
diewland / php_to_js.php
Last active January 3, 2017 08:32
Transform data from php to javascript
<script>
<?php
echo "var data = ".json_encode($data).";";
?>
</script>
@diewland
diewland / edit_git_config.sh
Created January 3, 2017 15:56
Edit .gitconfig global file
git config --global -e
@diewland
diewland / pre_debug.php
Created January 4, 2017 07:27
Debug php variable in good format
function pre_debug($data){
echo '<pre>'.print_r($data, true).'</pre>';
}
@diewland
diewland / get_combobox_index.js
Created January 21, 2017 15:26
Find combobox index on change event
$('#combobox').change(function(){
var idx = $(this)[0].selectedIndex;
console.log(idx);
});
@diewland
diewland / json_post.js
Created February 10, 2017 06:16
How to post json via jquery ajax ?
function jsonPost(url, data, callback){
$.ajax({
'url': url,
'type': 'post',
'contentType': 'application/json; charset=utf-8',
'dataType': 'json',
'data': JSON.stringify(data),
'success': function(a, b, c){
callback(a, b, c);
}
@diewland
diewland / jquery-datepicker-scope.js
Created February 15, 2017 16:41
jquery datepicker scope
// https://github.com/fengyuanchen/datepicker
$('#from_date').datepicker({
format: 'yyyy-mm-dd',
});
$('#to_date').datepicker({
format: 'yyyy-mm-dd',
});
$('#from_date').change(function(){
$('#to_date').datepicker('setStartDate', $(this).val());
});