Skip to content

Instantly share code, notes, and snippets.

@ValentinFunk
ValentinFunk / sv_mixin_trailchecker.lua
Created October 11, 2017 14:34
Mixin demonstration for PS2 (place in addons/ps2_customization/lua/ps2/server
local TrailcheckerMixin = {}
function TrailcheckerMixin:included( klass )
local oldThink = klaas.Think
klass.Think = function(self)
oldThink(self)
if IsValid(self.trailEnt) then
local shouldDraw = hook.Run("PS2_VisualsShouldShow", self:GetOwner()) == false
self.trailEnt:SetNoDraw(not shouldDraw)
end
end
@ValentinFunk
ValentinFunk / retry-http.ts
Created September 10, 2017 10:57
Retry HTTP in RXJs
function retryHttp<T>(retryCount: number, shouldRetry: (error: { code: number }) => boolean) {
return (request$: Observable<T>): Observable<T> => request$.retryWhen(
errors$ => errors$.flatMap(error => {
if (shouldRetry(error)) {
return Observable.of(true).delay(1000);
}
return Observable.throw({ error: 'Error cannot be retried', originalError: error });
}).take(5)
.concat(Observable.throw(`Request failed after ${retryCount} retries.`))
@ValentinFunk
ValentinFunk / index.html
Last active September 4, 2017 14:55 — forked from anonymous/index.html
Get Exchange Rates from ECB, restricted by date, for each date (uses last rate for unknown days) and export as CSV. JSBin: https://jsbin.com/cetihotuzu
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/1.2.2/bluebird.js"></script>
<script src="https://cdn.jsdelivr.net/lodash/4/lodash.min.js"></script>
@ValentinFunk
ValentinFunk / UserModule.ts
Last active October 9, 2018 19:26
@ngrx/store and @ng-bootstrap/ng-bootstrap NgbModal
@NgModule({...})
export class UserModule {
constructor(
ngbModal: NgbModal,
modalService: ModalService,
store: Store<AppState>
) {
// Disallow closing the login modal if user is accessing a protected route as first page.
// (else they would get an empty page due to the auth guard)
let loginModalOptions = store.select(x => x.user.loginRequired)
@ValentinFunk
ValentinFunk / app.component.ts
Last active July 26, 2017 08:02
Angular2 Router Loading Screen
export class AppComponent {
routerLoading$: Observable<boolean>;
constructor(private router: Router) {
this.routerLoading$ = this.router.events.flatMap(event => {
if (event instanceof NavigationStart) {
return [true];
}
if (event instanceof NavigationEnd ||
event instanceof NavigationCancel ||
event instanceof NavigationError) {
@ValentinFunk
ValentinFunk / NetlifyServerPushPlugin.js
Last active May 4, 2024 04:24
Webpack - Generate Netlify HTTP2 Server Push _headers File when using the HtmlWebpackPlugin
/**
* Generate a Netlify HTTP2 Server Push configuration.
*
* Options:
* - headersFile {string} path to the _headers file that should be generated (relative to your output dir)
*/
function NetlifyServerPushPlugin(options) {
this.options = options;
}
@ValentinFunk
ValentinFunk / sh_jumppack.lua
Last active July 14, 2017 18:34
Jump Pack higher Jumps
ITEM.baseClass = "base_hat"
ITEM.PrintName = "Jump Pack"
ITEM.Description = "Makes you jump higher!"
ITEM.Price = {
points = 1000,
}
ITEM.static.validSlots = {
"Accessory",
}
@ValentinFunk
ValentinFunk / leaveSessionTracker.js
Last active July 3, 2017 18:39
Sends events to analytics in timeouts to improve session tracking
window.addEventListener('beforeunload',
function(){
ga('send', 'event', 'Website', 'Unload', {transport: 'beacon', nonInteraction:true});
}
);
var timeout = 1;
var startTime = new Date().getTime();
function startBeacon() {
var timeOnSite = (startTime - new Date().getTime()) / 1000;
@ValentinFunk
ValentinFunk / random.lua
Last active June 28, 2017 11:48
Give a random item from category
local function GiveRandomItemFromCategory( ply, categoryName )
local factory = Pointshop2.ItemFromCategoryFactory:new()
factory.settings = {
["ManualSettings.CategoryName"] = categoryName,
["BasicSettings.WeightedRandom"] = true
}
local item = factory:CreateItem( true )
return ply:PS2_EasyAddItem( item.class.className )
end
@ValentinFunk
ValentinFunk / print.lua
Last active June 27, 2017 11:15
Example for Pointshop2.com Drops and Crates custom lua crate and function to print all item class names.
local str = LibK._(Pointshop2.GetRegisteredItems()):chain()
:map(function(item)
return { className = item.className, name = item:GetPrintName() }
end)
:sort(function(a, b)
if tonumber(a.className) and tonumber(b.className) then
return tonumber(a.className) < tonumber(b.className)
elseif tonumber(a) and not tonumber(b) then
return false
else