Skip to content

Instantly share code, notes, and snippets.

View gnrfan's full-sized avatar

Antonio Ognio gnrfan

View GitHub Profile
#!/bin/bash
#
# A markdown previewer by Antonio Ognio <[email protected]>
#
# Should work in a UNIX-like system using Bash such as GNU/Linux or Mac OS X#
# It depends on the uuid and markdown commands.
# In Ubuntu just type this: apt-get install uuid markdown
#
UUID=$(uuid)
<?php
function npparse($values) {
$result = array();
$result['args'] = array();
$result['kwargs'] = array();
$key = NULL;
foreach($values as $v) {
if (!is_null($key)) {
$result['kwargs'][$key] = $v;
# Redis configuration file example
# Note on units: when memory size is needed, it is possible to specifiy
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
DEBUG:root:Entering the cycle 1/5.
DEBUG:root:Key will be deleted when it reaches the value of 10 after 9 increments.
DEBUG:root:Key incremented to 2. 8 increment(s) left before the key gets deleted.
DEBUG:root:Sleeping for 1 second(s)...
DEBUG:root:Key incremented to 3. 7 increment(s) left before the key gets deleted.
DEBUG:root:Sleeping for 2 second(s)...
DEBUG:root:Key incremented to 4. 6 increment(s) left before the key gets deleted.
DEBUG:root:Sleeping for 2 second(s)...
DEBUG:root:Key incremented to 5. 5 increment(s) left before the key gets deleted.
DEBUG:root:Sleeping for 1 second(s)...
@gnrfan
gnrfan / NSString+MD5HexDigest.h
Created March 20, 2011 16:45
Extending the NSString class with a MD5 hex digest method using a category
#import <Cocoa/Cocoa.h>
#import <CommonCrypto/CommonDigest.h>
@interface NSString (md5)
-(NSString *) md5HexDigest;
@end
@gnrfan
gnrfan / SHA1HashTest.java
Created May 30, 2011 23:56
Java Snippet: Calculate SHA-1 hash of a string
import java.security.MessageDigest;
class SHA1Hash {
public static String getHexDigest(String str) throws java.security.NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-1");
return byteArrayToHex(md.digest(str.getBytes()));
}
public static String byteArrayToHex(byte[] bytes) {
@gnrfan
gnrfan / ReflectionStaticMemberTest.java
Created May 31, 2011 00:00
Java Snippet: Dynamically access an static object property using the Reflection API
import java.lang.reflect.Field;
final class ContainerClass {
public static final String some_key = "Hello World";
}
public class ReflectionStaticMemberTest {
public static void main(String args[]) throws Exception {
Field prop = ContainerClass.class.getDeclaredField("some_key");
System.out.println(prop.get(null));
@gnrfan
gnrfan / htmlentities_01.py
Created May 31, 2011 00:04
Python snippet: unicode2htmlentities
# -*- coding: utf-8 -*-
from htmlentitydefs import codepoint2name
def unicode2htmlentities(u):
htmlentities = list()
for c in u:
if ord(c) < 128:
htmlentities.append(c)
else:
@gnrfan
gnrfan / escape_for_xml.py
Created May 31, 2011 00:17
Python snippet: Escape unicode characters to be included in XML elements
#!/usr/bin/env python
# -*- encoding: utf8 -*-
def escape_unicode_for_xml(str):
replacements = (
('<', '&lt;'),
('>', '&gt;'),
('"', '&quot;'),
)
@gnrfan
gnrfan / google-test.txt
Created May 31, 2011 00:36
Google test
Hi google this is test in order to learn how fast you index Github gists