Skip to content

Instantly share code, notes, and snippets.

View ymirpl's full-sized avatar

Marcin Mincer ymirpl

View GitHub Profile
#!/usr/bin/perl
use warnings;
use strict;
# args: login shell
sub change_shell {
my $username = shift;
my $shell = shift;
my @command = ("chsh", "-s ".$shell, $username );
system(@command) or print STDERR "Failed to chsh";
# hash: login, uid, pass, dir,
sub add_user {
my(%args) = %{$_[0]};
my $command = "adduser -m ";
if (defined $args{'uid'}) {
$command .= "-u ".$args{'uid'};
}
if (defined $args{'dir'}) {
set RETAILERS ordered := 1 .. 23;
set DIVISIONS;
set MATERIALS;
var oilMarket{i in 1 2 3};
var Agroup;
var Bgroup;
var spiritMarket;
param matrix;
@ymirpl
ymirpl / gist:1052094
Created June 28, 2011 20:21
Python unicode e-mail sending
#coding: utf-8
from cStringIO import StringIO
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header
from email import Charset
from email.generator import Generator
import smtplib
# Example address data
@ymirpl
ymirpl / gist:1610035
Created January 14, 2012 02:47
file 'appending' in haskell
main = do
handle <- openFile "todo.txt" ReadMode
(tempName, tempHandle) <- openTempFile "." "temp"
contents <- hGetContents handle
let todoTasks = lines contents
numberedTasks = zipWith (\n line -> show n ++ " - " ++
line) [0..] todoTasks
putStrLn "These are your TO-DO items:"
putStr $ unlines numberedTasks
putStrLn "Which one do you want to delete?"
@ymirpl
ymirpl / gist:1611056
Created January 14, 2012 11:26
cute data types
data Car a b c = Car { company :: a
, model :: b
, year :: c
} deriving (Show)
tellCar :: Car -> String
tellCar (Car {company = c, model = m, year = y} = "This " ++ c ++ " " ++ m ++ " was made in "
)
++ show y
@ymirpl
ymirpl / gist:1613621
Created January 15, 2012 00:41
Parser maybe
module Parser where
import Data.Time
import Prelude hiding (catch)
import qualified Control.OldException as C
-- funkcja wczytujaca date z konsoli (waliduje jej poprawnosc)
-- return: IO Day - data podana z konsoli
getDay :: IO Day
/** One More Application
Imagine that you were creating a lottery application (or more likely, a lottery view within another application). You might have 10 views, each with a number, and you highlight each image as a number is drawn. In this case, you’d probably have ten instance variables, maybe named numberView1, numberView2, all the way to numberView10. To light up the views, you could have a large if…else or switch block, comparing the new value to all the values 1–10:
**/
int nextNum = arc4random() % 10 } 1; // Random number generator, 1–10
switch (nextNum) {
case 1:
// Highlight
break;
// etc.
}
/** One More Application
Imagine that you were creating a lottery application (or more likely, a lottery view within another application). You might have 10 views, each with a number, and you highlight each image as a number is drawn. In this case, you’d probably have ten instance variables, maybe named numberView1, numberView2, all the way to numberView10. To light up the views, you could have a large if…else or switch block, comparing the new value to all the values 1–10:
**/
int nextNum = arc4random() % 10 } 1; // Random number generator, 1–10
switch (nextNum) {
case 1:
// Highlight
break;
// etc.
}
{
"SyncDictionaries": [
{ "Occasion_Types":
[
{
"is_deleted": false,
"id": 40,