"You don't know where your shadow will fall", Somebody.
Programming
How to capitalize letters on bash shell script
12 years ago
It’s easy just use the tr command to lower, upper or capital case.
Here is an example…
1 2 3 4 5 6 7 8 9 | function toCapital { for x in $* do echo -n ${x:0:1} | tr '[a-z]' '[A-Z]' | xargs echo -n echo -n ${x:1} | tr '[A-Z]' '[a-z]' | xargs echo -n echo -n " " done } |
To test the function just call it:
1 | toCapital yuCa aMigo |
The output is:
Yuca Amigo
Hope it’s useful.
Autenticación LDAP en JAVA
03 years ago
*** Click Here to Download the JAVA code ***
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | /*** * ARCHIVO: test.java * USO: Autenticación de un usuario LDAP * AUTOR: Olaf Reitmaier <olafrv@gmail.com> (07 de Octubre de 2008) */ import java.util.Hashtable; import javax.naming.*; import javax.naming.directory.*; // java test ldap.dem.int dc=dem,dc=int uid usuario clave // java test ldap.dem.int dc=dem,dc=int mobile cedula clave class test{ public static void main(String args[]){ String servidor = args[0]; String dn_base = args[1]; String campo_unico = args[2]; String valor = args[3]; String clave = args[4]; String dn = LDAP.buscarDN(servidor, dn_base, campo_unico, valor); boolean autenticado = LDAP.autenticarDN(servidor, dn_base, dn, clave); if (autenticado){ System.out.println("Autenticado."); }else{ System.out.println("No Autenticado."); } } } final class LDAP{ public LDAP(){} /** * Busca el DN de un usuario utilizando un campo unico * en un directorio LDAP * * @param servidor X.Y.Z.W o FQDN * @param dn_base dc=dem,dc=int * @param campo_unico uid, gid, etc de la entrada * @param valor valor del campo unico */ public static final String buscarDN(String servidor, String dn_base, String campo_unico, String valor){ Hashtable entorno = new Hashtable(11); entorno.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory"); entorno.put(Context.PROVIDER_URL, "ldaps://" + servidor.toString() + ":636/" + dn_base); entorno.put(Context.SECURITY_AUTHENTICATION, "none"); String[] atributos = {"dn"}; //Lista de atributos resultado SearchControls controles = new SearchControls(); //Motor de búsqueda controles.setReturningAttributes(atributos); // Establecer atributos de resultado controles.setSearchScope(SearchControls.SUBTREE_SCOPE); //Alcance String filtro = "(" + campo_unico.toString() + "=" + valor.toString() + ")"; //Filtro String dn = null; try { DirContext contexto = new InitialDirContext(entorno); NamingEnumeration resultado = contexto.search("", filtro, controles); SearchResult item = (SearchResult) resultado.next(); dn = item.getName() + "," + dn_base; //String tmp = item.getAttributes().toString(); //System.out.println("Atributos" + tmp); //System.out.println("dn: " + dn); } catch (Exception e) { System.out.println("Error desconocido 1 !!!"); e.printStackTrace(); } return dn; } /** * Autentica un usuario contra un directorio LDAP * * @param servidor X.Y.Z.W o FQDN * @param dn_base dc=example,dc=com * @param dn_usuario uid=joe,ou=Usuarios,ou=Personas,dc=example,dc=com (utilizar buscarDN con uid) * @param clave 123456 */ public static final boolean autenticarDN(String servidor, String dn_base, String dn_usuario, String clave){ boolean autenticado = false; Hashtable entorno = new Hashtable(11); entorno.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); entorno.put(Context.PROVIDER_URL, "ldaps://"+servidor+":636/"+dn_base); entorno.put(Context.SECURITY_AUTHENTICATION, "simple"); entorno.put(Context.SECURITY_PRINCIPAL, dn_usuario); entorno.put(Context.SECURITY_CREDENTIALS, clave.toString()); try { DirContext contexto = new InitialDirContext(entorno); autenticado = true; } catch (AuthenticationException authEx) { System.out.println("Clave incorrecta!!!"); } catch (Exception e) { System.out.println("Error desconocido 2 !!!"); e.printStackTrace(); } return autenticado; } } |
Algoritmo rústico de Tic-Tac-Toe para QBASIC, Powerbasic y Justbasic
03 years ago
by olafrv
in Programming
A continuación tres (3) implementaciones rudimentarias del juego Tic-Tac-Toe (o “la vieja” como lo conozco) de los años 1996 (QBasic), 1999 (Powerbasic) y 2007 (traducción para Justbasic).
Uno de los primeros y espantosos pero divertidos programas que diseñe e implementé:
Saludos.-