Skip to content

Instantly share code, notes, and snippets.

@newpolaris
newpolaris / dxgl.cpp
Last active November 17, 2020 13:51 — forked from mmozeiko/dxgl.c
WGL_NV_DX_interop2 example
// NV_DX_interop : https://www.khronos.org/registry/OpenGL/extensions/NV/WGL_NV_DX_interop.txt
// NV_DX_interop2 : https://www.khronos.org/registry/OpenGL/extensions/NV/WGL_NV_DX_interop2.txt
// mmonzeiko's : https://gist.github.com/mmozeiko/c99f9891ce723234854f0919bfd88eae
#include <Windows.h>
#include <d3d11.h>
#include <GL/GL.h>
#include <GL/glext.h>
#include <GL/wglext.h>
@newpolaris
newpolaris / gray.cc
Created February 12, 2020 06:32 — forked from jiafulow/gray.cc
C++ Gray code
//
// Code from "Numerical Recipe in C (2nd edition)" by Press et al.
// Chapter 20.2 pg.896
//
#include <cstdint>
#include <iostream>
// Return the Gray code of n
uint64_t gray(uint64_t n)
@newpolaris
newpolaris / GLView.h
Created November 13, 2019 01:09 — forked from recp/GLView.h
Cocoa: Custom OpenGL View
/*
* Copyright (c), Recep Aslantas. All rights reserved.
*/
#import <Cocoa/Cocoa.h>
@protocol GLViewDelegate;
@interface GLView : NSView {
NSOpenGLContext * m_openGLContext;
@newpolaris
newpolaris / sfti_ch06_exercises.scala
Created January 7, 2017 03:01 — forked from parambirs/sfti_ch06_exercises.scala
Scala for the Impatient: Chapter 6 exercises solutions
object sfti extends App {
// 1.
object Conversions {
def inchesToCentimeters(in: Double) = 2.54*in
def gallonsToLiters(gal: Double) = 3.78541 * gal
def milesToKilometers(mi: Double) = 1.60934 * mi
}
// 2.
@newpolaris
newpolaris / sfti_ch05_exercises.scala
Created January 6, 2017 15:18 — forked from parambirs/sfti_ch05_exercises.scala
Scala for the Impatient: Chapter 5 exercises solutions
object sfti extends App {
// 1. Improve the Counter class in Section 5.1, "Simple Classes and Parameterless
// Methods," on page 51 so that it doesn't turn negative at Int.MaxValue.
class Counter {
private var value = 0
def increment() {
if (Int.MaxValue > value)
value += 1
}
def current() = value
import util.Random
import java.awt.datatransfer._
import scala.collection.mutable._
import java.util.TimeZone._
import java.awt.datatransfer._
object sfti extends App {
// 1. Write a code snippet that sets a to an array of n random integers between 0
// (inclusive) and n (exclusive).
val n = 10
object sfti extends App {
// 1. Set up a map of prices for a number of gizmos that you covet. Then produce
// a second map with the same keys and the prices at a 10 percent discount.
val gizmos = Map("iPod" -> 20000, "iPhone" -> 45000, "iPad" -> 30000, "iMac" -> 85000)
val discounted = for ((name, price) <- gizmos) yield (name, 0.9*price)
println(s"ex1 : $discounted")
// 2. Write a program that reads words from a file. Use a mutable map to count
// how often each word appears. To read the words, simply use a java.util.Scanner:
// val in = new java.util.Scanner(java.io.File("myfile.txt"))