Skip to content

Instantly share code, notes, and snippets.

@piccaso
piccaso / gist:2603879
Created May 5, 2012 16:37
parsing dd.mm.yyyy hh:ss (tt.mm.jjjj ss:mm) date (used in austria)
<?php
function parse_austrian_date($date,$output='U'){
$date = DateTime::createFromFormat('d.m.Y H:i', $date);
if($date === false) return false;
return $date->format($output);
}
echo parse_austrian_date('1.2.12 24:14','d.m.Y H:i:s');
@piccaso
piccaso / lcd_example.c
Created May 5, 2012 16:44
LCD example using new-liquidcrystal with a ciruit from 3g1l.com.
#include <LiquidCrystal_SR.h>
LiquidCrystal_SR lcd(8,7,TWO_WIRE);
// | |
// | \-- Clock Pin
// \---- Data/Enable Pin
// Creat a set of new characters
byte armsUp[8] = {
0b00100,0b01010,0b00100,0b10101,0b01110,0b00100,0b00100,0b01010};
@piccaso
piccaso / main.cs
Created October 13, 2012 23:01
regex 'reduce path' & y/n question
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
//using Sharpduino;
//using Sharpduino.Constants;
namespace ConsoleApplication1
{
@piccaso
piccaso / gist:4179759
Created December 1, 2012 00:30
win32 GetLastInputInfo C# example
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
namespace GetLastUserInput
{
public class GetLastUserInput
{
private struct LASTINPUTINFO
{
<?php
function preg_extract($pattern,$subject,$n=1,$default=''){
if(preg_match($pattern, $subject, $m)){
if (isset($m[$n])) return $m[$n];
}
return $default;
}
#! /bin/sh -e
### BEGIN INIT INFO
# Provides: compasswatcher
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop the compass watch process for each directory
### END INIT INFO
@piccaso
piccaso / ssh.cs
Last active December 7, 2022 07:07
ssh.net Example - Keybased Authentication, File Upload, Shell Commands
/*
get SSH.NET (BSD License: http://sshnet.codeplex.com/license)
with NuGet:
>Install-Package SSH.NET -Version 2013.4.7
or just get the dll from here: http://j.mp/sshNet
*/
using System;
@piccaso
piccaso / drupal-7-patch-SA-CORE-2014-005-D7.sh
Created October 18, 2014 15:12
patching Drupal 7 SA-CORE-2014-005-D7
wget -O /tmp/SA-CORE-2014-005-D7.patch https://www.drupal.org/files/issues/SA-CORE-2014-005-D7.patch && chmod 0600 /tmp/SA-CORE-2014-005-D7.patch
cd /var/www
find -path '*/includes/database/database.inc'
#make backups
for f in $( find -path '*/includes/database/database.inc' ); do cp -av $f $f.backup-$(date +"%Y-%m-%d-%H%M%S"); done
#dry run
for f in $( find -path '*/includes/database/database.inc' ); do patch --dry-run $f < /tmp/SA-CORE-2014-005-D7.patch; done
@piccaso
piccaso / openscad-sinus-animation.scad
Last active August 29, 2015 14:15
Using sinus for animation in OpenSCAD
/* result: http://i.imgur.com/PfutWmN.gif */
t=sin($t*180); /* $t==0 && t==0, $t==0.5 && t==1, $t==1 && t==0 */
n=t*.5;
for(l = [0:3]){ /* = 4 layers */
translate([n*(1.1*l)+(.1*l),0,0]) cube([.1,1,1]);
}
'use strict';
angular.module("ngLocale", [], ["$provide", function($provide) {
var PLURAL_CATEGORY = {ZERO: "zero", ONE: "one", TWO: "two", FEW: "few", MANY: "many", OTHER: "other"};
function getDecimals(n) {
n = n + '';
var i = n.indexOf('.');
return (i == -1) ? 0 : n.length - i - 1;
}
function getVF(n, opt_precision) {