Skip to content

Instantly share code, notes, and snippets.

View davidsommer's full-sized avatar

David Sommer davidsommer

View GitHub Profile
@davidsommer
davidsommer / sshConnector.sh
Last active May 12, 2020 12:57
Connect Script to connect to SSH with a Password fetched from OSX Keychain
#!/bin/bash
if [ "$1" == "-h" ]; then
echo " To run this script, you need the following things:"
echo " * Install sshpass "
echo " brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb"
echo " * generate a generic password in your keychain"
echo " Usage: add-generic-password [-a account] [-s service] [-w password] [options...] [-A|-T appPath] [keychain]"
echo " -a Specify account name (required)"
echo " -c Specify item creator (optional four-character code)"
@davidsommer
davidsommer / umsatzProUser.sql
Created December 16, 2015 15:05
Get Total Amount per User
SELECT customer_id, order_cnt, totalBestellwertUser
FROM (
SELECT customer_id,
COUNT(customer_id) AS order_cnt,
SUM(totalBestellwert) AS totalBestellwertUser
FROM (SELECT so.customer_id,
YEAR(so.created_at) AS year_ordered,
SUM(base_grand_total) AS totalBestellwert,
group_concat(si.sku SEPARATOR ',') AS skus
FROM `sales_flat_order` AS so
@davidsommer
davidsommer / user.sql
Last active July 21, 2016 20:26
Magento User data
SELECT
t.cid AS mid,
t.email_ AS email,
t.group_id_ AS group_id,
GROUP_CONCAT(t.fname_ SEPARATOR '') AS fname,
GROUP_CONCAT(t.lname_ SEPARATOR '') AS lname,
t.street_ AS street,
GROUP_CONCAT(t.city_ SEPARATOR '') AS city,
GROUP_CONCAT(t.state_code_ SEPARATOR '') AS state_code,
GROUP_CONCAT(t.zip_ SEPARATOR '') AS zip,
@davidsommer
davidsommer / mysql_table_size.sql
Created January 17, 2014 12:25
Mysql Table size
SELECT CONCAT(table_schema, '.', table_name),
CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows,
CONCAT(ROUND(data_length / ( 1024 * 1024 ), 2), 'MB') DATA,
CONCAT(ROUND(index_length / ( 1024 * 1024 ), 2), 'MB') idx,
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 ), 2), 'MB') total_size,
ROUND(index_length / data_length, 2) idxfrac
FROM information_schema.TABLES
-- WHERE table_schema = 'YOUR DATABASE NAME'
@davidsommer
davidsommer / mergeExcel.java
Created December 5, 2013 14:01
Merge a List of Excel Files with POI Copies all Sheets, Fields of a List of Excel Files into a new one
public static void mergeExcelFiles(File file, List<FileInputStream> list) throws IOException {
HSSFWorkbook book = new HSSFWorkbook();
HSSFSheet sheet = book.createSheet(file.getName());
for (FileInputStream fin : list) {
HSSFWorkbook b = new HSSFWorkbook(fin);
for (int i = 0; i < b.getNumberOfSheets(); i++) {
copySheets(book, sheet, b.getSheetAt(i));
}
}
<!DOCTYPE html>
<html>
<head>
<title>Leaflet</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.3.1/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.3.1/leaflet.js"></script>
<script src="http://maps.google.com/maps/api/js?v=3.2&sensor=false"></script>
<script src="http://matchingnotes.com/javascripts/leaflet-google.js"></script>
</head>
<body>
@davidsommer
davidsommer / gist:6826042
Created October 4, 2013 13:36 — forked from michailb/gist:6825726
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
<?php
$page_id = "YOUR PAGE-ID";
$xml = @simplexml_load_file("http://api.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id=".$page_id."") or die ("a lot");
$fans = $xml->page->fan_count;
echo $fans;
?>
//MAKE FIRST WORD BOLD
public class WebScanner {
// These are the variables that hold the URL and the
// image when done loading
private BufferedImage img;
private URL url;
// This is a bit more complicated, but I explained it above.
private SwingWorker<BufferedImage, Void> worker = new SwingWorker<BufferedImage, Void>() {
@Override
@davidsommer
davidsommer / getURLVariable.js
Created August 13, 2013 05:56
Usage - Example URL: http://www.example.com/index.php?id=1&image=awesome.jpg Calling getQueryVariable("id") - would return "1". Calling getQueryVariable("image") - would return "awesome.jpg".
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){
return pair[1];
}
}
return(false);