Skip to content

Instantly share code, notes, and snippets.

@peponi
peponi / count_win_or_mac_requests.rb
Created June 8, 2012 13:22
count how many clients come over OS X or Windows
# https://github.com/visionmedia/user-agent
agent = Agent.new request.user_agent
User.os_name = agent.os
User.count(:conditions => "os_name = 'OS X' OR os_name = 'OS X 10.4' OR os_name = 'OS X 10.5' OR os_name = 'OS X 10.6' OR os_name = 'OS X 10.7'")
User.count(:conditions => "os_name = 'Windows 7' OR os_name = 'Windows Vista' OR os_name = 'Windows 2000' OR os_name = 'Windows XP' OR os_name = 'Windows 2003'")
@peponi
peponi / gist:2895602
Created June 8, 2012 13:26
update database over heroku console
heroku console User.last.update_attribute :credits,"42" --app YOUR_APP_NAME
@peponi
peponi / LazyHighCharts_example.rb
Created June 13, 2012 09:35
use the HighCharts lib in Rails by using LazyHighCharts
# find the reference here -> http://www.highcharts.com/ref
# github.com/michelson/lazy_high_charts
require "lazy_high_charts"
class CreateGraph
def init()
mess = []
@peponi
peponi / download_ebook_pages_Curl.sh
Created July 17, 2012 13:45
download ebook pages via Curl
curl http://www-cs-students.stanford.edu/~blynn/gitmagic/intl/de/ch0[1-9].html -o "ch0#1.html"
@peponi
peponi / GetTimeDiff.php
Created August 22, 2012 13:12
Convert UNIX timestamp to days hours minute seconds
<?php
function GetTimeDiff($timestamp)
{
$how_log_ago = '';
$seconds = time() - $timestamp;
$minutes = (int)($seconds / 60);
$hours = (int)($minutes / 60);
$days = (int)($hours / 24);
if ($days >= 1) {
$how_log_ago = $days . ' day' . ($days != 1 ? 's' : '');
@peponi
peponi / identi.ca_dumper.sh
Created December 8, 2012 13:28
identi.ca dump onliner
for i in `seq 1 26`; do wget "http://identi.ca/api/statuses/user_timeline.xml?screen_name=peponi&count=200&page=${i}" -O stream-${i}.xml ; sleep 2; done ;
@peponi
peponi / laravel_form_db_mapper.php
Last active December 16, 2015 09:28
a short snippet to map laravel form response to DB insert array <?php echo Form::input('text','alter') ?> input attr title needs to be the same like the db table row titles -> $table->integer('alter');
<?php
public function post_some_crap()
{
$result = Input::get();
/* ============= just a smal data maper snippit ================= */
// replace the table name in ::query('show columns from <tablename> ');
// got all rows as index from table
@peponi
peponi / js two dimension array.js
Created June 3, 2013 07:46
simple javascript two dimension array
// create an two dimension array
function Create2DArray(rows) {
var arr = [];
for (var i=0;i<rows;i++) {
arr[i] = [];
}
return arr;
}
@peponi
peponi / checkbox_multiline_label_align_correctio
Created July 9, 2013 07:49
checkbox multiline label align correctio
/* checkbox multiline label align correction */
label {
position:relative;
padding-left:22px;
display:block;
}
label input[type=checkbox] {
position:absolute;
top:2px;
@peponi
peponi / frontend_editing
Created July 22, 2013 10:04
frontend_editing
<html>
<head>
<title></title>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<style>
.edit{width: 100px;margin-left:20px;}
input
{