Skip to content

Instantly share code, notes, and snippets.

View lambdaman2's full-sized avatar

Lambdaman lambdaman2

View GitHub Profile
@lambdaman2
lambdaman2 / Snipplr-25239.txt
Created October 1, 2012 12:48
Starting and stopping MySQL
// Stop
mysqladmin -u root -p shutdown
// Start
./bin/safe_mysqld &
@lambdaman2
lambdaman2 / Snipplr-38193.py
Created October 1, 2012 12:48
Python: Start a quick webserver from any directory:
python -m SimpleHTTPServer 8000
@lambdaman2
lambdaman2 / Snipplr-34623.py
Created October 1, 2012 12:48
Python: sorting a dictionary
You could use:
sorted(dictionaryObject.items(), key=lambda x: x[1] )
@lambdaman2
lambdaman2 / Snipplr-56327.bash
Created October 1, 2012 12:48
Bash: Shell : How to rename/mv large number of files
for i in *.JPG; do mv $i ${i%.JPG}.tmp; done
@lambdaman2
lambdaman2 / Snipplr-28218.scm
Created October 1, 2012 12:48
Scheme: scheme: replace a string
(define string-replace
(lambda (s match replacement)
(let ((ll (string->list s))
(match1 (char match))
(replacement1 (char replacement)))
(if (= (string-length match) 1)
(let ((z (map (lambda (x)
(if (equal? x match1)
replacement1
x))
@lambdaman2
lambdaman2 / Snipplr-28007.scm
Created October 1, 2012 12:48
Scheme: Scheme: find a substring
(let loop ((i 0)
(j 20) ;; comparison value: it decreases at each recursion (except the first one)
(topvalue 20)) ;; komodo value : must be equal to j at the beginning
(let ((txt "Toyota denies previous banking problem is safety"))
(if (equal? (- topvalue i) j) ;; the first time
(loop (+ i 1) j topvalue)
(begin (print (substring txt (- topvalue i) j))
(if (string=? (substring txt (- topvalue i) j) " ")
(string-append (substring txt 0 (- topvalue i))
"\n"
@lambdaman2
lambdaman2 / Snipplr-24676.scm
Created October 1, 2012 12:48
Scheme: scheme: check for optional arguments
(define-macro (p r . otherstuff)
`(if (null? (list ,@otherstuff))
(print ,r)
(print ,@otherstuff)))
(p 'c 'ciao)
@lambdaman2
lambdaman2 / Snipplr-44947.js
Created October 1, 2012 12:48
JavaScript: Running scripts ciclically
<html>
<body>
<input type="text" id="clock" />
<script language=javascript>
var int=self.setInterval("clock()",1000);
function clock()
{
var d=new Date();
var t=d.toLocaleTimeString();
@lambdaman2
lambdaman2 / Snipplr-56710.py
Created October 1, 2012 12:48
Python: RGB Gradation Chart Generator
import string
colors = ("00", "33", "66", "99", "CC", "FF")
masks = ("#00~00", "#~~00", "#~0000", "#~00~", "#0000~", "#00~~", "#FF~00", "#~~~")
f = open("colortest-gradation.html", 'w')
f.write("<html><head><title>RGB Gradation</title></head><body bgcolor='black'><tt><b>")
f.write("<p><font color='white'>Gentle gradations through RGB color:</font></p>\n")
@lambdaman2
lambdaman2 / Snipplr-56709.py
Created October 1, 2012 12:48
Python: RGB Color Gradation Function
import string
def make_color_tuple( color ):
"""
turn something like "#000000" into 0,0,0
or "#FFFFFF into "255,255,255"
"""
R = color[1:3]
G = color[3:5]
B = color[5:7]