code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
package main
import (
"fmt"
"math"
"strconv"
"strings"
)
func d2d(d float64) float64 { return math.Mod(d, 360) }
func g2g(g float64) float64 { return math.Mod(g, 400) }
func m2m(m float64) float64 { return math.Mod(m, 6400) }
func r2r(r float64) float64 { return math.Mod(r, 2*math.Pi) }
func d2g(d... | 1,141Angles (geometric), normalization and conversion | 0go | onc8q |
void processFile(char* name){
int i,records;
double diff,b1,b2;
FILE* fp = fopen(name,);
fscanf(fp,,&records);
for(i=0;i<records;i++){
fscanf(fp,,&b1,&b2);
diff = fmod(b2-b1,360.0);
printf(,b2,b1,(diff<-180)?diff+360:((diff>=180)?diff-360:diff));
}
fclose(fp);
}
int main(int argC,char* argV[])
{
do... | 1,142Angle difference between two bearings | 5c | 5gauk |
import java.lang.reflect.Constructor
abstract class Angle implements Comparable<? extends Angle> {
double value
Angle(double value = 0) { this.value = normalize(value) }
abstract Number unitCircle()
abstract String unitName()
Number normalize(double n) { n % this.unitCircle() }
def <B exte... | 1,141Angles (geometric), normalization and conversion | 7groovy | xs3wl |
double alpha, accl, omega = 0, E;
struct timeval tv;
double elappsed() {
struct timeval now;
gettimeofday(&now, 0);
int ret = (now.tv_sec - tv.tv_sec) * 1000000
+ now.tv_usec - tv.tv_usec;
tv = now;
return ret / 1.e6;
}
void resize(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadI... | 1,143Animate a pendulum | 5c | q0zxc |
import Text.Printf
class (Num a, Fractional a, RealFrac a) => Angle a where
fullTurn :: a
mkAngle :: Double -> a
value :: a -> Double
fromTurn :: Double -> a
toTurn :: a -> Double
normalize :: a -> a
fromTurn t = angle t * fullTurn
toTurn a = value $ a / fullTurn
normalize a = a `modulo` ful... | 1,141Angles (geometric), normalization and conversion | 8haskell | 2upll |
import java.text.DecimalFormat; | 1,141Angles (geometric), normalization and conversion | 9java | 6mr3z |
typedef unsigned int uint;
int main(int argc, char **argv)
{
uint top = atoi(argv[1]);
uint *divsum = malloc((top + 1) * sizeof(*divsum));
uint pows[32] = {1, 0};
for (uint i = 0; i <= top; i++) divsum[i] = 1;
for (uint p = 2; p+p <= top; p++) {
if (divsum[p] > 1) {
divsum[p] -= p;
co... | 1,144Amicable pairs | 5c | 3yuza |
(defn angle-difference [a b]
(let [r (mod (- b a) 360)]
(if (>= r 180)
(- r 360)
r)))
(angle-difference 20 45)
(angle-difference -45 45)
(angle-difference -85 90)
(angle-difference -95 90)
(angle-difference -70099.74 29840.67) | 1,142Angle difference between two bearings | 6clojure | jks7m |
function angleConv(deg, inp, out) {
inp = inp.toLowerCase();
out = out.toLowerCase();
const D = 360,
G = 400,
M = 6400,
R = 2 * Math.PI; | 1,141Angles (geometric), normalization and conversion | 10javascript | lvbcf |
(ns pendulum
(:import
(javax.swing JFrame)
(java.awt Canvas Graphics Color)))
(def length 200)
(def width (* 2 (+ 50 length)))
(def height (* 3 (/ length 2)))
(def dt 0.1)
(def g 9.812)
(def k (- (/ g length)))
(def anchor-x (/ width 2))
(def anchor-y (/ height 8))
(def angle (atom (/ (Math/PI) 2)))
(defn d... | 1,143Animate a pendulum | 6clojure | id9om |
import java.text.DecimalFormat as DF
const val DEGREE = 360.0
const val GRADIAN = 400.0
const val MIL = 6400.0
const val RADIAN = 2 * Math.PI
fun d2d(a: Double) = a % DEGREE
fun d2g(a: Double) = a * (GRADIAN / DEGREE)
fun d2m(a: Double) = a * (MIL / DEGREE)
fun d2r(a: Double) = a * (RADIAN / 360)
fun g2d(a: Double) =... | 1,141Angles (geometric), normalization and conversion | 11kotlin | dtvnz |
(ns example
(:gen-class))
(defn factors [n]
" Find the proper factors of a number "
(into (sorted-set)
(mapcat (fn [x] (if (= x 1) [x] [x (/ n x)]))
(filter #(zero? (rem n %)) (range 1 (inc (Math/sqrt n)))) )))
(def find-pairs (into #{}
(for [n (range 2 20000)
... | 1,144Amicable pairs | 6clojure | c279b |
package main
import (
"log"
"time"
"github.com/gdamore/tcell"
)
const (
msg = "Hello World! "
x0, y0 = 8, 3
shiftsPerSecond = 4
clicksToExit = 5
)
func main() {
s, err := tcell.NewScreen()
if err != nil {
log.Fatal(err)
}
if err = s.Init();... | 1,140Animation | 0go | awt1f |
range = { degrees=360, gradians=400, mils=6400, radians=2.0*math.pi }
function convert(value, fromunit, tounit)
return math.fmod(value * range[tounit] / range[fromunit], range[tounit])
end
testvalues = { -2, -1, 0, 1, 2, 6.2831853, 16, 57.2957795, 359, 399, 6399, 1000000 }
testunits = { "degrees", "gradians", "mils"... | 1,141Angles (geometric), normalization and conversion | 1lua | fzudp |
import Graphics.HGL.Units (Time, Point, Size, )
import Graphics.HGL.Draw.Monad (Graphic, )
import Graphics.HGL.Draw.Text
import Graphics.HGL.Draw.Font
import Graphics.HGL.Window
import Graphics.HGL.Run
import Graphics.HGL.Utils
import Control.Exception (bracket, )
runAnim = runGraphics $
bracket
(openWindowEx "Bas... | 1,140Animation | 8haskell | z6gt0 |
package main
import (
"fmt"
"io/ioutil"
"strings"
"sort"
)
func deranged(a, b string) bool {
if len(a) != len(b) {
return false
}
for i := range(a) {
if a[i] == b[i] { return false }
}
return true
}
func main() {
buf, _ := ioutil.ReadFile("unixdict.txt")
words := strings.Split(string(buf), "\n")
m ... | 1,139Anagrams/Deranged anagrams | 0go | ex3a6 |
use strict;
use warnings;
use feature 'say';
use POSIX 'fmod';
my $tau = 2 * 4*atan2(1, 1);
my @units = (
{ code => 'd', name => 'degrees' , number => 360 },
{ code => 'g', name => 'gradians', number => 400 },
{ code => 'm', name => 'mills' , number => 6400 },
{ code => 'r', name => 'radians' , num... | 1,141Angles (geometric), normalization and conversion | 2perl | jk07f |
def map = new TreeMap<Integer,Map<String,List<String>>>()
new URL('http: | 1,139Anagrams/Deranged anagrams | 7groovy | kpnh7 |
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
public class Rotate {
private ... | 1,140Animation | 9java | onl8d |
import Data.List (maximumBy, sort, unfoldr)
import Data.Ord (comparing)
import qualified Data.Map as M
import qualified Data.Set as S
groupBySig :: [String] -> [(String, S.Set String)]
groupBySig = map ((,) . sort <*> S.singleton)
equivs :: [(String, S.Set String)] -> [[String]]
equivs = map (S.toList . snd) . M.t... | 1,139Anagrams/Deranged anagrams | 8haskell | 3y7zj |
PI = 3.141592653589793
TWO_PI = 6.283185307179586
def normalize2deg(a):
while a < 0: a += 360
while a >= 360: a -= 360
return a
def normalize2grad(a):
while a < 0: a += 400
while a >= 400: a -= 400
return a
def normalize2mil(a):
while a < 0: a += 6400
while a >= 6400: a -= 6400
return a
def normalize... | 1,141Angles (geometric), normalization and conversion | 3python | hb8jw |
null | 1,140Animation | 11kotlin | xs6ws |
package main
import (
"fmt"
"math/big"
"strings"
)
func factorial(n int64) *big.Int {
var z big.Int
return z.MulRange(1, n)
}
var one = big.NewInt(1)
var three = big.NewInt(3)
var six = big.NewInt(6)
var ten = big.NewInt(10)
var seventy = big.NewInt(70)
func almkvistGiullera(n int64, print bool)... | 1,145Almkvist-Giullera formula for pi | 0go | nfmi1 |
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class DerangedAnagrams {
public static void main(String[] args) throws IOExce... | 1,139Anagrams/Deranged anagrams | 9java | idvos |
package main
import "fmt"
func main() {
for _, n := range []int{0, 1, 2, 3, 4, 5, 10, 40, -1} {
f, ok := arFib(n)
if ok {
fmt.Printf("fib%d =%d\n", n, f)
} else {
fmt.Println("fib undefined for negative numbers")
}
}
}
func arFib(n int) (int, bool) {
... | 1,138Anonymous recursion | 0go | s8cqa |
module Angles
BASES = { => 360, => 400, => 6400, => Math::PI*2 , => 24 }
def self.method_missing(meth, angle)
from, to = BASES.values_at(*meth.to_s.split())
raise NoMethodError, meth if (from.nil? or to.nil?)
mod = (angle.to_f * to / from) % to
angle < 0? mod - to: mod
end
end
names = Angle... | 1,141Angles (geometric), normalization and conversion | 14ruby | b1ikq |
import Control.Monad
import Data.Number.CReal
import GHC.Integer
import Text.Printf
iterations = 52
main = do
printf "N.%44s%4s%s\n"
"Integral part of Nth term" "10^" "=Actual value of Nth term"
forM_ [0..9] $ \n ->
printf "%d.%44d%4d%s\n" n
(almkvistGiulleraIntegral ... | 1,145Almkvist-Giullera formula for pi | 8haskell | u4kv2 |
#!/usr/bin/env js
function main() {
var wordList = read('unixdict.txt').split(/\s+/);
var anagrams = findAnagrams(wordList);
var derangedAnagrams = findDerangedAnagrams(anagrams);
var longestPair = findLongestDerangedPair(derangedAnagrams);
print(longestPair.join(' '));
}
function findLongestDera... | 1,139Anagrams/Deranged anagrams | 10javascript | z6rt2 |
def fib = {
assert it > -1
{i -> i < 2 ? i: {j -> owner.call(j)}(i-1) + {k -> owner.call(k)}(i-2)}(it)
} | 1,138Anonymous recursion | 7groovy | aw31p |
use std::{
marker::PhantomData,
f64::consts::PI,
};
pub trait AngleUnit: Copy {
const TURN: f64;
const NAME: &'static str;
}
macro_rules! unit {
($name:ident, $value:expr, $string:expr) => (
#[derive(Debug, Copy, Clone)]
struct $name;
impl AngleUnit for $name {
... | 1,141Angles (geometric), normalization and conversion | 15rust | panbu |
import Foundation
func normalize(_ f: Double, N: Double) -> Double {
var a = f
while a < -N { a += N }
while a >= N { a -= N }
return a
}
func normalizeToDeg(_ f: Double) -> Double {
return normalize(f, N: 360)
}
func normalizeToGrad(_ f: Double) -> Double {
return normalize(f, N: 400)
}
func normaliz... | 1,141Angles (geometric), normalization and conversion | 17swift | kpohx |
import esMain from 'es-main';
import { BigFloat, set_precision as SetPrecision } from 'bigfloat-esnext';
const Iterations = 52;
export const demo = function() {
SetPrecision(-75);
console.log("N." + "Integral part of Nth term".padStart(45) + " 10^ =Actual value of Nth term");
for (let i=0; i<10; i++) {
let ... | 1,145Almkvist-Giullera formula for pi | 10javascript | v5h25 |
package main
import "fmt"
type bearing float64
var testCases = []struct{ b1, b2 bearing }{
{20, 45},
{-45, 45},
{-85, 90},
{-95, 90},
{-45, 125},
{-45, 145},
{29.4803, -88.6381},
{-78.3251, -159.036},
}
func main() {
for _, tc := range testCases {
fmt.Println(tc.b2.Sub(tc... | 1,142Angle difference between two bearings | 0go | 8im0g |
fib :: Integer -> Maybe Integer
fib n
| n < 0 = Nothing
| otherwise = Just $ real n
where real 0 = 1
real 1 = 1
real n = real (n-1) + real (n-2) | 1,138Anonymous recursion | 8haskell | 9lpmo |
function love.load()
text = "Hello World! "
length = string.len(text)
update_time = 0.3
timer = 0
right_direction = true
local width, height = love.graphics.getDimensions( )
local size = 100
local font = love.graphics.setNewFont( size )
local twidth = font:getWidth( text )
local theight = font:getHeight(... | 1,140Animation | 1lua | q0yx0 |
def angleDifferenceA(double b1, double b2) {
r = (b2 - b1) % 360.0
(r > 180.0 ? r - 360.0
: r <= -180.0 ? r + 360.0
: r)
} | 1,142Angle difference between two bearings | 7groovy | wqtel |
import java.awt.*;
import javax.swing.*;
class Pendulum extends JPanel implements Runnable {
private angle = Math.PI / 2;
private length;
Pendulum(length) {
this.length = length;
setDoubleBuffered(true);
}
@Override
void paint(Graphics g) {
g.setColor(Color.WHITE);
... | 1,143Animate a pendulum | 7groovy | y9g6o |
use strict;
use warnings;
use feature qw(say);
use Math::AnyNum qw(:overload factorial);
sub almkvist_giullera_integral {
my($n) = @_;
(32 * (14*$n * (38*$n + 9) + 9) * factorial(6*$n)) / (3*factorial($n)**6);
}
sub almkvist_giullera {
my($n) = @_;
almkvist_giullera_integral($n) / (10**(6*$n + 3));
}
... | 1,145Almkvist-Giullera formula for pi | 2perl | kpqhc |
import Control.Monad (join)
import Data.Bifunctor (bimap)
import Text.Printf (printf)
type Radians = Float
type Degrees = Float
bearingDelta :: (Radians, Radians) -> Radians
bearingDelta (a, b)
=
sign * acos ((ax * bx) + (ay * by))
where
(ax, ay) = (sin a, cos a)
(bx, by) = (sin b, cos b)
sign
... | 1,142Angle difference between two bearings | 8haskell | lvkch |
package main
import (
"github.com/google/gxui"
"github.com/google/gxui/drivers/gl"
"github.com/google/gxui/math"
"github.com/google/gxui/themes/dark"
omath "math"
"time"
) | 1,143Animate a pendulum | 0go | 2ukl7 |
null | 1,139Anagrams/Deranged anagrams | 11kotlin | q0mx1 |
import Graphics.HGL.Draw.Monad (Graphic, )
import Graphics.HGL.Draw.Picture
import Graphics.HGL.Utils
import Graphics.HGL.Window
import Graphics.HGL.Run
import Control.Exception (bracket, )
import Control.Arrow
toInt = fromIntegral.round
pendulum = runGraphics $
bracket
(openWindowEx "Pendulum animation task" ... | 1,143Animate a pendulum | 8haskell | awn1g |
import mpmath as mp
with mp.workdps(72):
def integer_term(n):
p = 532 * n * n + 126 * n + 9
return (p * 2**5 * mp.factorial(6 * n)) / (3 * mp.factorial(n)**6)
def exponent_term(n):
return -(mp.mpf() * n + 3)
def nthterm(n):
return integer_term(n) * mp.mpf()**exponent_term... | 1,145Almkvist-Giullera formula for pi | 3python | b1skr |
public class AngleDifference {
public static double getDifference(double b1, double b2) {
double r = (b2 - b1) % 360.0;
if (r < -180.0)
r += 360.0;
if (r >= 180.0)
r -= 360.0;
return r;
}
public static void main(String[] args) {
System.out.pr... | 1,142Angle difference between two bearings | 9java | 3y4zg |
public static long fib(int n) {
if (n < 0)
throw new IllegalArgumentException("n can not be a negative number");
return new Object() {
private long fibInner(int n) {
return (n < 2) ? n : (fibInner(n - 1) + fibInner(n - 2));
}
}.fibInner(n);
} | 1,138Anonymous recursion | 9java | t3rf9 |
function relativeBearing(b1Rad, b2Rad)
{
b1y = Math.cos(b1Rad);
b1x = Math.sin(b1Rad);
b2y = Math.cos(b2Rad);
b2x = Math.sin(b2Rad);
crossp = b1y * b2x - b2y * b1x;
dotp = b1x * b2x + b1y * b2y;
if(crossp > 0.)
return Math.acos(dotp);
return -Math.acos(dotp);
}
function test()
{
var deg2rad = 3.14159265/180... | 1,142Angle difference between two bearings | 10javascript | c2h9j |
string.tacnoc = function(str) | 1,139Anagrams/Deranged anagrams | 1lua | s89q8 |
function fibo(n) {
if (n < 0) { throw "Argument cannot be negative"; }
return (function(n) {
return (n < 2) ? 1 : arguments.callee(n-1) + arguments.callee(n-2);
})(n);
} | 1,138Anonymous recursion | 10javascript | mcbyv |
use Tk;
use Time::HiRes qw(sleep);
my $msg = 'Hello World! ';
my $first = '.+';
my $second = '.';
my $mw = Tk::MainWindow->new(-title => 'Animated side-scroller',-bg=>"white");
$mw->geometry ("400x150+0+0");
$mw->optionAdd('*Label.font', 'Courier 24 bold' );
my $scroller = $mw->Label(-text => "$msg")->grid(-row... | 1,140Animation | 2perl | 2u1lf |
(mapc #'use-package '(#:toadstool #:toadstool-system))
(defstruct (red-black-tree (:constructor tree (color left val right)))
color left val right)
(defcomponent tree (operator macro-mixin))
(defexpand tree (color left val right)
`(class red-black-tree red-black-tree-color ,color
red-black... | 1,146Algebraic data types | 6clojure | fz9dm |
int kprime(int n, int k)
{
int p, f = 0;
for (p = 2; f < k && p*p <= n; p++)
while (0 == n % p)
n /= p, f++;
return f + (n > 1) == k;
}
int main(void)
{
int i, c, k;
for (k = 1; k <= 5; k++) {
printf(, k);
for (i = 2, c = 0; c < 10; i++)
if (kprime(i, k)) {
printf(, i);
c++;
}
putchar... | 1,147Almost prime | 5c | s8dq5 |
import java.awt.*;
import javax.swing.*;
public class Pendulum extends JPanel implements Runnable {
private double angle = Math.PI / 2;
private int length;
public Pendulum(int length) {
this.length = length;
setDoubleBuffered(true);
}
@Override
public void paint(Graphics g) {... | 1,143Animate a pendulum | 9java | jkq7c |
<html><head>
<title>Pendulum</title>
</head><body style="background: gray;">
<canvas id="canvas" width="600" height="600">
<p>Sorry, your browser does not support the <canvas> used to display the pendulum animation.</p>
</canvas>
<script>
function PendulumSim(length_m, gravity_mps2, initialAngle_rad, times... | 1,143Animate a pendulum | 10javascript | 1eip7 |
(ns clojure.examples.almostprime
(:gen-class))
(defn divisors [n]
" Finds divisors by looping through integers 2, 3,...i.. up to sqrt (n) [note: rather than compute sqrt(), test with i*i <=n] "
(let [div (some #(if (= 0 (mod n %)) % nil) (take-while #(<= (* % %) n) (iterate inc 2)))]
(if div ... | 1,147Almost prime | 6clojure | nf6ik |
import java.awt.*
import java.util.concurrent.*
import javax.swing.*
class Pendulum(private val length: Int) : JPanel(), Runnable {
init {
val f = JFrame("Pendulum")
f.add(this)
f.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
f.pack()
f.isVisible = true
isDoubleBuffer... | 1,143Animate a pendulum | 11kotlin | 5g1ua |
typedef const char * amb_t;
amb_t amb(size_t argc, ...)
{
amb_t *choices;
va_list ap;
int i;
if(argc) {
choices = malloc(argc*sizeof(amb_t));
va_start(ap, argc);
i = 0;
do { choices[i] = va_arg(ap, amb_t); } while(++i < argc);
va_end(ap);
i = 0;
do { TRY(choices[i]); } while(++i <... | 1,148Amb | 5c | ont80 |
import sys
from PyQt5.QtCore import QBasicTimer, Qt
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QApplication, QLabel
class Marquee(QLabel):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.right_to_left_direction = True
self.initUI()
self.timer = QBasicT... | 1,140Animation | 3python | v5a29 |
package main
import "fmt"
type Color string
const (
R Color = "R"
B = "B"
)
type Tree interface {
ins(x int) Tree
}
type E struct{}
func (_ E) ins(x int) Tree {
return T{R, E{}, x, E{}}
}
func (_ E) String() string {
return "E"
}
type T struct {
cl Color
le Tree
aa int
... | 1,146Algebraic data types | 0go | 5gkul |
null | 1,142Angle difference between two bearings | 11kotlin | nflij |
package main
import "fmt"
func pfacSum(i int) int {
sum := 0
for p := 1; p <= i/2; p++ {
if i%p == 0 {
sum += p
}
}
return sum
}
func main() {
var a[20000]int
for i := 1; i < 20000; i++ {
a[i] = pfacSum(i)
}
fmt.Println("The amicable pairs below 20,... | 1,144Amicable pairs | 0go | b10kh |
char *name, *password;
...
LDAP *ld = ldap_init(, 389);
ldap_simple_bind_s(ld, name, password);
LDAPMessage **result;
ldap_search_s(ld, , LDAP_SCOPE_SUBTREE,
,
NULL,
0,
result);
ldap_msgfree(*result);
ldap_unbind(ld); | 1,149Active Directory/Search for a user | 5c | 1expj |
data Color = R | B
data Tree a = E | T Color (Tree a) a (Tree a)
balance :: Color -> Tree a -> a -> Tree a -> Tree a
balance B (T R (T R a x b) y c ) z d = T R (T B a x b) y (T B c z d)
balance B (T R a x (T R b y c)) z d = T R (T B a x b) ... | 1,146Algebraic data types | 8haskell | xsnw4 |
bearing = {degrees = 0} | 1,142Angle difference between two bearings | 1lua | dt2nq |
fun fib(n: Int): Int {
require(n >= 0)
fun fib1(k: Int, a: Int, b: Int): Int =
if (k == 0) a else fib1(k - 1, b, a + b)
return fib1(n, 0, 1)
}
fun main(args: Array<String>) {
for (i in 0..20) print("${fib(i)} ")
println()
} | 1,138Anonymous recursion | 11kotlin | onv8z |
divisors :: (Integral a) => a -> [a]
divisors n = filter ((0 ==) . (n `mod`)) [1 .. (n `div` 2)]
main :: IO ()
main = do
let range = [1 .. 20000 :: Int]
divs = zip range $ map (sum . divisors) range
pairs = [(n, m) | (n, nd) <- divs, (m, md) <- divs,
n < m, nd == m, md == n]
print pairs | 1,144Amicable pairs | 8haskell | dtcn4 |
rotate_string <- function(x, forwards)
{
nchx <- nchar(x)
if(forwards)
{
paste(substr(x, nchx, nchx), substr(x, 1, nchx - 1), sep = "")
} else
{
paste(substr(x, 2, nchx), substr(x, 1, 1), sep = "")
}
}
handle_rotate_label <- function(obj, interval = 1... | 1,140Animation | 13r | 9lkmg |
(ns amb
(:use clojure.contrib.monads))
(defn amb [wss]
(let [valid-word (fn [w1 w2]
(if (and w1 (= (last w1) (first w2)))
(str w1 " " w2)))]
(filter #(reduce valid-word %)
(with-monad sequence-m (m-seq wss)))))
amb> (amb '(("the" "that" "a") ("frog" "ele... | 1,148Amb | 6clojure | t3mfv |
package main
import (
"log"
"github.com/jtblin/go-ldap-client"
)
func main() {
client := &ldap.LDAPClient{
Base: "dc=example,dc=com",
Host: "ldap.example.com",
Port: 389,
GroupFilter: "(memberUid=%s)",
}
defer client.Close()
err := client.Co... | 1,149Active Directory/Search for a user | 0go | y9l64 |
sub deranged {
my @a = split('', shift);
my @b = split('', shift);
for (0 .. $
$a[$_] eq $b[$_] and return;
}
return 1
}
sub find_deranged {
for my $i ( 0 .. $
for my $j ( $i+1 .. $
... | 1,139Anagrams/Deranged anagrams | 2perl | v5e20 |
function degToRad( d )
return d * 0.01745329251
end
function love.load()
g = love.graphics
rodLen, gravity, velocity, acceleration = 260, 3, 0, 0
halfWid, damp = g.getWidth() / 2, .989
posX, posY, angle = halfWid
TWO_PI, angle = math.pi * 2, degToRad( 90 )
end
function love.update( dt )
ac... | 1,143Animate a pendulum | 1lua | 4ra5c |
module Main (main) where
import Data.Foldable (for_)
import qualified Data.Text.Encoding as Text (encodeUtf8)
import Ldap.Client (Attr(..), Filter(..))
import qualified Ldap.Client as Ldap (Dn(..), Host(..), search, with, typesOnly)
main :: IO ()
main = do
entries <- Ldap.with (Ldap.Plain "loc... | 1,149Active Directory/Search for a user | 8haskell | hb1ju |
import java.io.IOException;
import org.apache.directory.api.ldap.model.cursor.CursorException;
import org.apache.directory.api.ldap.model.cursor.EntryCursor;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.m... | 1,149Active Directory/Search for a user | 9java | 5g7uf |
null | 1,146Algebraic data types | 11kotlin | rj1go |
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
public class AmicablePairs {
public static void main(String[] args) {
int limit = 20_000;
Map<Long, Long> map = LongStream.rangeClosed(1, limit)
.paral... | 1,144Amicable pairs | 9java | s8zq0 |
...
char *name, *password;
...
LDAP *ld = ldap_init(, 389);
ldap_simple_bind_s(ld, name, password);
... after done with it...
ldap_unbind(ld); | 1,150Active Directory/Connect | 5c | t36f4 |
unsigned long long bruteForceProperDivisorSum(unsigned long long n){
unsigned long long i,sum = 0;
for(i=1;i<(n+1)/2;i++)
if(n%i==0 && n!=i)
sum += i;
return sum;
}
void printSeries(unsigned long long* arr,int size,char* type){
int i;
printf(,arr[0],type);
for(i=0;i<size-1;i++)
printf(,arr[i]);
print... | 1,151Aliquot sequence classifications | 5c | 2uulo |
(function (max) { | 1,144Amicable pairs | 10javascript | nf9iy |
use strict;
use warnings;
use Net::LDAP;
my $ldap = Net::LDAP->new( 'ldap://ldap.forumsys.com' ) or die "$@";
my $mesg = $ldap->bind( "cn=read-only-admin,dc=example,dc=com",
password => "password" );
$mesg->code and die $mesg->error;
my $srch = $ldap->search( base => "d... | 1,149Active Directory/Search for a user | 2perl | xs8w8 |
char *sortedWord(const char *word, char *wbuf)
{
char *p1, *p2, *endwrd;
char t;
int swaps;
strcpy(wbuf, word);
endwrd = wbuf+strlen(wbuf);
do {
swaps = 0;
p1 = wbuf; p2 = endwrd-1;
while (p1<p2) {
if (*p2 > *p1) {
t = *p2; *p2 = *p1; *p1 = t;
... | 1,152Anagrams | 5c | pa1by |
<?php
$words = file(
'http:
FILE_IGNORE_NEW_LINES
);
$length = 0;
foreach ($words as $word) {
$chars = str_split($word);
sort($chars);
$chars = implode(, $chars);
$length = strlen($chars);
$anagrams[$length][$chars][] = $word;
}
krsort($anagrams);
foreach ($anagrams as $anagram) {
$fi... | 1,139Anagrams/Deranged anagrams | 12php | 0ocsp |
local function Y(x) return (function (f) return f(f) end)(function(y) return x(function(z) return y(y)(z) end) end) end
return Y(function(fibs)
return function(n)
return n < 2 and 1 or fibs(n - 1) + fibs(n - 2)
end
end) | 1,138Anonymous recursion | 1lua | iduot |
require 'tk'
$str = TkVariable.new()
$dir = :right
def animate
$str.value = shift_char($str.value, $dir)
$root.after(125) {animate}
end
def shift_char(str, dir)
case dir
when :right then str[-1,1] + str[0..-2]
when :left then str[1..-1] + str[0,1]
end
end
$root = TkRoot.new( => )
TkLabel.new($root) do
... | 1,140Animation | 14ruby | 5gwuj |
package main
import (
"log"
"github.com/jtblin/go-ldap-client"
)
func main() {
client := &ldap.LDAPClient{
Base: "dc=example,dc=com",
Host: "ldap.example.com",
Port: 389,
UseSSL: false,
BindDN: "uid=readonlyuser,ou=People,dc=examp... | 1,150Active Directory/Connect | 0go | hbpjq |
module Main (main) where
import Data.Foldable (for_)
import qualified Data.Text.Encoding as Text (encodeUtf8)
import Ldap.Client (Attr(..), Filter(..))
import qualified Ldap.Client as Ldap (Dn(..), Host(..), search, with, typesOnly)
main :: IO ()
main = do
entries <- Ldap.with (Ldap.Plain "loc... | 1,150Active Directory/Connect | 8haskell | idfor |
import java.io.IOException;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.ldap.client.api.LdapConnection;
import org.apache.directory.ldap.client.api.LdapNetworkConnection;
public class LdapConnectionDemo {
public static void main(String[] args) throws LdapExcepti... | 1,150Active Directory/Connect | 9java | xs0wy |
<?php
$l = ldap_connect('ldap.example.com');
ldap_set_option($l, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($l, LDAP_OPT_REFERRALS, false);
$bind = ldap_bind($l, 'me@example.com', 'password');
$base = 'dc=example, dc=com';
$criteria = '(&(objectClass=user)(sAMAccountName=username))';
$attributes = array('display... | 1,149Active Directory/Search for a user | 12php | 2u4l4 |
long long c[100];
void coef(int n)
{
int i, j;
if (n < 0 || n > 63) abort();
for (c[i=0] = 1; i < n; c[0] = -c[0], i++)
for (c[1 + (j=i)] = 1; j > 0; j--)
c[j] = c[j-1] - c[j];
}
int is_prime(int n)
{
int i;
coef(n);
c[0] += 1, c[i=n] -= 1;
while (i-- && !(c[i] % n));
return i < 0;
}
void show(int ... | 1,153AKS test for primes | 5c | wqwec |
void memoizeIsPrime( bool * result, const int N )
{
result[2] = true;
result[3] = true;
int prime[N];
prime[0] = 3;
int end = 1;
for (int n = 5; n < N; n += 2)
{
bool n_is_prime = true;
for (int i = 0; i < end; ++i)
{
const int PRIME = prime[i];
... | 1,154Additive primes | 5c | clm9c |
use 5.010;
use strict;
use warnings qw(FATAL all);
my $balanced = qr{([^<>,]++|<(?-1),(?-1),(?-1),(?-1)>)};
my ($a, $b, $c, $d, $x, $y, $z) = map +qr((?<$_>$balanced)),
'a'..'d', 'x'..'z';
my $col = qr{(?<col>[RB])};
sub balance {
local $_ = shift;
if( /^<B,<R,<R,$a,$x,$b>,$y,$c>,$z,$d>\z/ or
/^<B,<R,$a,$x,<R,$b... | 1,146Algebraic data types | 2perl | dtmnw |
#[cfg(feature = "gtk")]
mod graphical {
extern crate gtk;
use self::gtk::traits::*;
use self::gtk::{Inhibit, Window, WindowType};
use std::ops::Not;
use std::sync::{Arc, RwLock};
pub fn create_window() {
gtk::init().expect("Failed to initialize GTK");
let window = Window::new(... | 1,140Animation | 15rust | 4rx5u |
import scala.actors.Actor.{actor, loop, reactWithin, exit}
import scala.actors.TIMEOUT
import scala.swing.{SimpleSwingApplication, MainFrame, Label}
import scala.swing.event.MouseClicked
case object Revert
object BasicAnimation extends SimpleSwingApplication {
val label = new Label("Hello World! ")
val rotator = ... | 1,140Animation | 16scala | 7h0r9 |
import org.apache.directory.api.ldap.model.exception.LdapException
import org.apache.directory.ldap.client.api.LdapNetworkConnection
import java.io.IOException
import java.util.logging.Level
import java.util.logging.Logger
class LDAP(map: Map<String, String>) {
fun run() {
var connection: LdapNetworkConnec... | 1,150Active Directory/Connect | 11kotlin | paeb6 |
import ldap
l = ldap.initialize()
try:
l.protocol_version = ldap.VERSION3
l.set_option(ldap.OPT_REFERRALS, 0)
bind = l.simple_bind_s(, )
base =
criteria =
attributes = ['displayName', 'company']
result = l.search_s(base, ldap.SCOPE_SUBTREE, criteria, attributes)
results = [entry fo... | 1,149Active Directory/Search for a user | 3python | q0oxi |
package main
import (
"bufio"
"fmt"
"log"
"os"
)
type SomeStruct struct {
runtimeFields map[string]string
}
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
ss := SomeStruct{make(map[string]string)}
scanner := bufio.NewScanner(os.Stdin)
fmt.Pri... | 1,155Add a variable to a class instance at runtime | 0go | xqawf |
package main
import (
"fmt"
"unsafe"
)
func main() {
myVar := 3.14
myPointer := &myVar
fmt.Println("Address:", myPointer, &myVar)
fmt.Printf("Address:%p%p\n", myPointer, &myVar)
var addr64 int64
var addr32 int32
ptr := unsafe.Pointer(myPointer)
if unsafe.Sizeof(ptr) <= unsafe.Sizeof(addr64) {
addr64 = in... | 1,156Address of a variable | 0go | kbrhz |
use Net::LDAP;
my $ldap = Net::LDAP->new('ldap://ldap.example.com') or die $@;
my $mesg = $ldap->bind( $bind_dn, password => $bind_pass ); | 1,150Active Directory/Connect | 2perl | y9c6u |
typedef struct {
double (*func)(double);
struct timeval start;
double v, last_v, last_t;
pthread_t id;
} integ_t, *integ;
void update(integ x)
{
struct timeval tv;
double t, v, (*f)(double);
f = x->func;
gettimeofday(&tv, 0);
t = ((tv.tv_sec - x->start.tv_sec) * 1000000
+ tv.tv_usec - x->start.tv_usec) * 1... | 1,157Active object | 5c | 6yd32 |
require 'rubygems'
require 'net/ldap'
ldap = Net::LDAP.new(:host => 'hostname', :base => 'base')
ldap.authenticate('bind_dn', 'bind_pass')
filter = Net::LDAP::Filter.pres('objectclass')
filter &= Net::LDAP::Filter.eq('sn','Jackman')
filter = Net::LDAP::Filter.construct('(&(objectclass=*)(sn=Jackman))')
results = ld... | 1,149Active Directory/Search for a user | 14ruby | 0onsu |
import org.apache.directory.api.ldap.model.message.SearchScope
import org.apache.directory.ldap.client.api.{LdapConnection, LdapNetworkConnection}
object LdapSearchDemo extends App {
class LdapSearch {
def demonstrateSearch(): Unit = {
val conn = new LdapNetworkConnection("localhost", 11389)
try {... | 1,149Active Directory/Search for a user | 16scala | nfzic |
class A {
final x = { it + 25 }
private map = new HashMap()
Object get(String key) { map[key] }
void set(String key, Object value) { map[key] = value }
} | 1,155Add a variable to a class instance at runtime | 7groovy | p1hbo |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.