Skip to content

Instantly share code, notes, and snippets.

Language Package Manager CLI Manifest file Lock file
Ruby Bundler bundle Gemfile Gemfile.lock
JavaScript npm npm package.json package-lock.json
Yarn yarn package.json yarn.lock
Swift Swift Package Manager swift package Package.swift Package.resolved
CocoaPods pod Podfile Podfile.lock
import * as repl from 'repl';
function myEval(cmd, context, filename, callback) {
callback(null, cmd.trim());
}
function myWriter(output) {
return output;
}
@wulab
wulab / fizzbuzz.scm
Last active May 3, 2021 17:17
Write a program that prints the numbers from 1 to 100. But for multiples of three print Fizz instead of the number and for the multiples of five print Buzz. For numbers which are multiples of both three and five print FizzBuzz.
(define (fizzbuzz)
(define (fizzbuzz-iter counter max-count)
(print counter)
(if (>= counter max-count)
'done
(fizzbuzz-iter (+ counter 1) max-count)))
(define (print n)
(cond ((and (divisible n 3) (divisible n 5)) (write-line 'fizzbuzz))
((divisible n 3) (write-line 'fizz))
((divisible n 5) (write-line 'buzz))
@wulab
wulab / sicp_ex13.scm
Last active April 28, 2021 15:12
Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.
(define (square x) (* x x))
(define (sum-of-squares x y)
(+ (square x) (square y)))
(define (max x y)
(if (> x y) x y))
(define (min x y)
(if (< x y) x y))
def graduated_price(users)
if users <= 3
return 0
elsif users <= 10
return graduated_price(3) + 5 * (users - 3) + 15
elsif users <= 14
return graduated_price(10)
elsif users <= 17
return graduated_price(14) + 25
elsif users <= 24
const lessonList = [...]
const timeslotRange = [...]
const roomRange = [...]
const timeTable = new TimeTable()
const timeLimit = 5000
const startTime = new Date()
let currentTime = startTime
let bestScore = 0
activity(friday, 'september townhall').
activity(saturday, 'learn prolog facts').
activity(sunday, 'learn prolog rules').
weekend(saturday).
weekend(sunday).
weekend_activity(A) :-
activity(D, A),
weekend(D).
@wulab
wulab / deriv.rb
Last active September 27, 2020 15:13
Derivative of a Function
def deriv(f)
dx = 0.000001
->(x) { (f.(x+dx) - f.(x)) / dx }
end
f = ->(x) { x*x + 2*x + 1 }
g = deriv(f)
g.(2)
# => 6.000001000927568
from elasticsearch import Elasticsearch
import re
import subprocess
import time
def build_doc():
doc = {}
doc.update(current_batt())
doc.update(current_time())
from elasticsearch import Elasticsearch
import time
THERMAL_ZONES = [
"/sys/class/thermal/thermal_zone0",
"/sys/class/thermal/thermal_zone1",
"/sys/class/thermal/thermal_zone2",
]