Skip to content

Instantly share code, notes, and snippets.

@yamamaya
yamamaya / gist:8199905
Last active January 1, 2016 20:49
書初め2014
<script type="text/javascript">
sin = Math.sin;
cos = Math.cos;
for ( i = 0 ; i < 8 ; i++ ) {
document.write( String.fromCharCode( Math.round( 13202.5+540.8*sin(i)+14948.3*cos(i)+7978.9*sin(2*i)-406.5*cos(2*i)-2614.3*sin(3*i)-5237.5*cos(3*i)+1847.2*sin(4*i)+2334.7*cos(4*i)+10577.7*sin(5*i)-2711*cos(5*i)+11858.1*sin(6*i)+21036.9*cos(6*i)+7818.5*sin(7*i)+1605.5*cos(7*i)-8761*sin(8*i)-9131.8*cos(8*i) ) ) ) ;
}
</script>
#include <inttypes.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
void TimerHandler( union sigval sv ) {
// Timer1 interrupt handler
void __attribute__( ( interrupt ) ) _T1Interrupt( ) {
flag1 = 1;
flag2 = 1;
IFS0bits.T1IF = 0;
}
while ( 1 ) {
IEC0bits.T1IE = 0; // Disable Timer1 interrupt
f1 = flag1;
void UART1Init() {
U1BRG = 25;
U1MODE = 0;
U1MODEbits.BRGH = 1;
U1STA = 0;
U1MODEbits.UARTEN = 1;
U1STAbits.UTXEN = 0;
IFS0bits.U1RXIF = 0;
IEC0bits.U1RXIE = 1;
}
void __attribute__((interrupt, auto_psv)) _U1RXInterrupt() {
char c = (char)U1RXREG;
IFS0bits.U1RXIF = 0;
// Do something
}
@yamamaya
yamamaya / gist:217ddb03ada591a01bf5
Created June 13, 2014 11:42
convert bare word to string literal
#define message NYA!
// Preprocessor magic!
#define _STRING(str) #str
#define STRING(str) _STRING(str)
int main(void) {
printf( "%s\n", STRING( message ) );
return 0;
}
@yamamaya
yamamaya / DrawCircle.v
Created June 29, 2014 07:11
コードの化石の断片
module DrawCircle(
input CLOCK,
input nRESET,
input START,
input signed [11:0] X0,
input signed [10:0] Y0,
input signed [11:0] R,
input FILL,
output signed [11:0] X,
output signed [10:0] Y,
$.ajax( {
type: "GET",
url: "/command.cgi?op=190&CTRL=0x1f&DATA=" + value,
cache: true,
dataType: "json",
timeout: 3000,
beforeSend: function( jqXHR, settings ) {
jqXHR.setRequestHeader( "If-Modified-Since", "Thu, 01 Jan 1970 00:00:00 GMT" );
}
} ).done( function( data, textStatus, jqXHR ) {
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>IDisposable Implementation</Title>
<Shortcut>idisp</Shortcut>
<Description>
How Dispose(bool) should be implemented in a class that uses managed
and native resources.
</Description>
@yamamaya
yamamaya / gist:4bf14905e3d0469594630de1d21f968e
Created August 1, 2016 06:36
What exception should I throw?
namespace Sample1 {
class Program {
static void Main( string[] args ) {
Class1 class1 = new Class1();
Console.WriteLine( class1[ DateTime.Now.Second ].ToString() );
}
}
public class Class1 {